Search in sources :

Example 1 with BridgeRequestScope

use of com.liferay.faces.bridge.scope.internal.BridgeRequestScope in project liferay-faces-bridge-impl by liferay.

the class BridgePhaseBaseImpl method init.

protected void init(PortletRequest portletRequest, PortletResponse portletResponse, Bridge.PortletPhase portletPhase) {
    // Save the Bridge.PortletPhase as a request attribute so that it can be picked up by the
    // BridgeRequestAttributeListener.
    portletRequest.setAttribute(Bridge.PORTLET_LIFECYCLE_PHASE, portletPhase);
    // Save the PortletConfig as a request attribute.
    portletRequest.setAttribute(PortletConfig.class.getName(), portletConfig);
    // Save the BridgeConfig as a request attribute.
    portletRequest.setAttribute(BridgeConfig.class.getName(), bridgeConfig);
    // Initialize the bridge request scope.
    initBridgeRequestScope(portletRequest, portletResponse, portletPhase);
    // Save the BridgeRequestScope as a request attribute.
    portletRequest.setAttribute(BridgeRequestScope.class.getName(), bridgeRequestScope);
    // Save the IncongruityContext as a request attribute.
    portletRequest.setAttribute(IncongruityContext.class.getName(), incongruityContext);
    // Save the BridgeContext as a request attribute for legacy versions of ICEfaces.
    setBridgeContextAttribute(portletRequest);
    // Get the FacesContext.
    facesContext = getFacesContext(portletRequest, portletResponse, facesLifecycle);
    // If not set by a previous request, then set the default viewIdHistory for the portlet modes.
    for (String portletMode : PortletModeHelper.PORTLET_MODE_NAMES) {
        String attributeName = Bridge.VIEWID_HISTORY + "." + portletMode;
        PortletSession portletSession = portletRequest.getPortletSession();
        if (portletSession.getAttribute(attributeName) == null) {
            Map<String, String> defaultViewIdMap = ViewUtil.getDefaultViewIdMap(portletConfig);
            portletSession.setAttribute(attributeName, defaultViewIdMap.get(portletMode));
        }
    }
}
Also used : PortletSession(javax.portlet.PortletSession) IncongruityContext(com.liferay.faces.bridge.context.internal.IncongruityContext) PortletConfig(javax.portlet.PortletConfig) BridgeConfig(javax.portlet.faces.BridgeConfig) BridgeRequestScope(com.liferay.faces.bridge.scope.internal.BridgeRequestScope)

Example 2 with BridgeRequestScope

use of com.liferay.faces.bridge.scope.internal.BridgeRequestScope in project liferay-faces-bridge-impl by liferay.

the class BridgePhaseEventImpl method execute.

// Java 1.6+ @Override
@Override
public void execute() throws BridgeDefaultViewNotSpecifiedException, BridgeException {
    logger.debug(Logger.SEPARATOR);
    logger.debug("execute(EventRequest, EventResponse) portletName=[{0}]", portletName);
    String bridgeEventHandlerAttributeName = Bridge.BRIDGE_PACKAGE_PREFIX + portletName + "." + Bridge.BRIDGE_EVENT_HANDLER;
    BridgeEventHandler bridgeEventHandler = (BridgeEventHandler) portletContext.getAttribute(bridgeEventHandlerAttributeName);
    if (bridgeEventHandler == null) {
        bridgeEventHandler = BridgeEventHandlerFactory.getBridgeEventHandlerInstance(portletConfig);
    }
    try {
        // If there is a bridgeEventHandler registered in portlet.xml, then
        if (bridgeEventHandler != null) {
            init(eventRequest, eventResponse, Bridge.PortletPhase.EVENT_PHASE);
            // Restore the BridgeRequestScope that may have started during the ACTION_PHASE.
            bridgeRequestScope.restoreState(facesContext);
            // PROPOSED-FOR-BRIDGE3-API: https://issues.apache.org/jira/browse/PORTLETBRIDGE-202
            bridgeRequestScope.setPortletMode(eventRequest.getPortletMode());
            // Execute the JSF lifecycle so that ONLY the RESTORE_VIEW phase executes (note that this this is
            // accomplished by the IPCPhaseListener).
            facesLifecycle.execute(facesContext);
            throwQueuedExceptionIfNecessary(facesContext);
            // Set a flag on the bridge request scope indicating that the Faces Lifecycle has executed.
            bridgeRequestScope.setFacesLifecycleExecuted(true);
            // If there is a bridgeEventHandler registered in portlet.xml, then invoke the handler so that it
            // can process the event payload.
            logger.debug("Invoking {0} for class=[{1}]", bridgeEventHandlerAttributeName, bridgeEventHandler.getClass());
            Event event = eventRequest.getEvent();
            EventNavigationResult eventNavigationResult = bridgeEventHandler.handleEvent(facesContext, event);
            if (eventNavigationResult != null) {
                String oldViewId = facesContext.getViewRoot().getViewId();
                String fromAction = eventNavigationResult.getFromAction();
                String outcome = eventNavigationResult.getOutcome();
                logger.debug("Invoking navigationHandler fromAction=[{0}] outcome=[{1}]", fromAction, outcome);
                NavigationHandler navigationHandler = facesContext.getApplication().getNavigationHandler();
                navigationHandler.handleNavigation(facesContext, fromAction, outcome);
                String newViewId = facesContext.getViewRoot().getViewId();
                bridgeRequestScope.setNavigationOccurred(!oldViewId.equals(newViewId));
            }
            // Process the outgoing public render parameters.
            // TCK (eventControllerTest)
            processOutgoingPublicRenderParameters(facesLifecycle);
            // Save the faces view root and any messages in the faces context so that they can be restored during
            // the RENDER_PHASE of the portlet lifecycle.
            bridgeRequestScope.saveState(facesContext);
            // In accordance with Section 5.2.5 of the Spec, if a portlet mode change has occurred, then the
            // bridge request scope must not be maintained.
            // 
            // NOTE: THIS REQUIREMENT IS HANDLED BY THE RENDER PHASE since the current design relies on
            // BridgeRequestScope.restoreState(FacesContext) to detect portlet mode changes in some cases.
            // 
            // PROPOSE-FOR-BRIDGE3-SPEC: Although the spec does not mention the redirect case, the bridge request
            // scope must not be maintained if a redirect has occurred.
            // 
            // REDIRECT:
            // ---------
            // TCK (eventScopeNotRestoredRedirectTest)
            // TCK (redirectEventTest)
            // 
            // PORTLET MODE CHANGED:
            // ---------------------
            // TCK (eventScopeNotRestoredModeChangedTest)
            // TCK (encodeActionURLWithModeEventTest)
            // 
            // NON-REDIRECT / SAME PORTLET MODE:
            // ---------------------------------
            // TCK (eventPhaseListenerTest)
            // TCK (eventScopeRestoredTest)
            // TCK (eventControllerTest)
            // TCK (encodeActionURLJSFViewEventTest)
            // TCK (encodeActionURLWithParamEventTest)
            // TCK (encodeActionURLWithInvalidModeEventTest),
            // TCK (encodeActionURLWithWindowStateEventTest)
            // TCK (encodeActionURLWithInvalidWindowStateEventTest)
            // TCK (getRequestHeaderMapEventTest)
            // TCK (getRequestHeaderValuesMapEventTest)
            // TCK (getRequestCharacterEncodingEventTest)
            // TCK (getRequestContentTypeEventTest)
            // TCK (getResponseCharacterEncodingEventTest)
            // TCK (getResponseContentTypeEventTest)
            // Assume that the bridge request scope should be maintained from the EVENT_PHASE into the
            // RENDER_PHASE by utilizing render parameters.
            BridgeRequestScope.Transport bridgeRequestScopeTransport = BridgeRequestScope.Transport.RENDER_PARAMETER;
            Serializable eventPayload = event.getValue();
            // redirect.
            if ((eventPayload != null) && (eventPayload instanceof EventPayloadWrapper)) {
                EventPayloadWrapper eventPayloadWrapper = (EventPayloadWrapper) eventPayload;
                if (eventPayloadWrapper.isRedirect()) {
                    bridgeRequestScopeTransport = BridgeRequestScope.Transport.PORTLET_SESSION_ATTRIBUTE;
                }
            }
            maintainBridgeRequestScope(eventRequest, eventResponse, bridgeRequestScopeTransport);
        }
        // Maintain the render parameters set in the ACTION_PHASE so that they carry over to the RENDER_PHASE.
        maintainRenderParameters(eventRequest, eventResponse);
        // Spec 6.6 (Namespacing)
        if (bridgeEventHandler != null) {
            indicateNamespacingToConsumers(facesContext.getViewRoot(), eventResponse);
        }
    } catch (Throwable t) {
        throw new BridgeException(t);
    } finally {
        if (bridgeEventHandler != null) {
            cleanup(eventRequest);
        }
    }
}
Also used : BridgeException(javax.portlet.faces.BridgeException) Serializable(java.io.Serializable) EventPayloadWrapper(com.liferay.faces.bridge.event.EventPayloadWrapper) EventNavigationResult(javax.portlet.faces.event.EventNavigationResult) BridgeEventHandler(javax.portlet.faces.BridgeEventHandler) Event(javax.portlet.Event) NavigationHandler(javax.faces.application.NavigationHandler) BridgeRequestScope(com.liferay.faces.bridge.scope.internal.BridgeRequestScope)

Example 3 with BridgeRequestScope

use of com.liferay.faces.bridge.scope.internal.BridgeRequestScope in project liferay-faces-bridge-impl by liferay.

the class ActionResponseBridgeImpl method prepareForRedirect.

protected void prepareForRedirect() {
    // Update the PartialViewContext.
    FacesContext facesContext = FacesContext.getCurrentInstance();
    partialViewContextRenderAll(facesContext);
    // Set the response as "complete" in the FacesContext.
    facesContext.responseComplete();
    // Set a flag on the {@link BridgeRequestScope} indicating that a <redirect />
    // occurred which means that the request attributes should not be preserved.
    BridgeRequestScope bridgeRequestScope = RequestMapUtil.getBridgeRequestScope(facesContext);
    bridgeRequestScope.setRedirectOccurred(true);
}
Also used : FacesContext(javax.faces.context.FacesContext) BridgeRequestScope(com.liferay.faces.bridge.scope.internal.BridgeRequestScope)

Example 4 with BridgeRequestScope

use of com.liferay.faces.bridge.scope.internal.BridgeRequestScope in project liferay-faces-bridge-impl by liferay.

the class ActionResponseBridgeImpl method setPortletMode.

@Override
public void setPortletMode(PortletMode portletMode) throws PortletModeException {
    super.setPortletMode(portletMode);
    if (!initialPortletMode.equals(portletMode)) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        BridgeRequestScope bridgeRequestScope = RequestMapUtil.getBridgeRequestScope(facesContext);
        bridgeRequestScope.setPortletModeChanged(true);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) BridgeRequestScope(com.liferay.faces.bridge.scope.internal.BridgeRequestScope)

Aggregations

BridgeRequestScope (com.liferay.faces.bridge.scope.internal.BridgeRequestScope)4 FacesContext (javax.faces.context.FacesContext)2 IncongruityContext (com.liferay.faces.bridge.context.internal.IncongruityContext)1 EventPayloadWrapper (com.liferay.faces.bridge.event.EventPayloadWrapper)1 Serializable (java.io.Serializable)1 NavigationHandler (javax.faces.application.NavigationHandler)1 Event (javax.portlet.Event)1 PortletConfig (javax.portlet.PortletConfig)1 PortletSession (javax.portlet.PortletSession)1 BridgeConfig (javax.portlet.faces.BridgeConfig)1 BridgeEventHandler (javax.portlet.faces.BridgeEventHandler)1 BridgeException (javax.portlet.faces.BridgeException)1 EventNavigationResult (javax.portlet.faces.event.EventNavigationResult)1