Search in sources :

Example 1 with EventPayloadWrapper

use of com.liferay.faces.bridge.event.EventPayloadWrapper 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 2 with EventPayloadWrapper

use of com.liferay.faces.bridge.event.EventPayloadWrapper in project liferay-faces-bridge-impl by liferay.

the class CustomerSelectedEventHandler method handleEvent.

public EventNavigationResult handleEvent(FacesContext facesContext, Event event) {
    EventNavigationResult eventNavigationResult = null;
    String eventQName = event.getQName().toString();
    if (eventQName.equals("{http://liferay.com/events}ipc.customerSelected")) {
        Serializable value = event.getValue();
        // payload from the wrapper.
        if (value instanceof EventPayloadWrapper) {
            value = ((EventPayloadWrapper) value).getWrapped();
        }
        Customer customer = (Customer) value;
        BookingsModelBean bookingsModelBean = getBookingsModelBean(facesContext);
        bookingsModelBean.setCustomer(customer);
        String fromAction = null;
        String outcome = "ipc.customerSelected";
        eventNavigationResult = new EventNavigationResult(fromAction, outcome);
        logger.debug("Received event ipc.customerSelected for customerId=[{0}] firstName=[{1}] lastName=[{2}]", new Object[] { customer.getCustomerId(), customer.getFirstName(), customer.getLastName() });
    }
    return eventNavigationResult;
}
Also used : Serializable(java.io.Serializable) EventPayloadWrapper(com.liferay.faces.bridge.event.EventPayloadWrapper) Customer(com.liferay.faces.demos.dto.Customer) EventNavigationResult(javax.portlet.faces.event.EventNavigationResult) BookingsModelBean(com.liferay.faces.demos.bean.BookingsModelBean)

Aggregations

EventPayloadWrapper (com.liferay.faces.bridge.event.EventPayloadWrapper)2 Serializable (java.io.Serializable)2 EventNavigationResult (javax.portlet.faces.event.EventNavigationResult)2 BridgeRequestScope (com.liferay.faces.bridge.scope.internal.BridgeRequestScope)1 BookingsModelBean (com.liferay.faces.demos.bean.BookingsModelBean)1 Customer (com.liferay.faces.demos.dto.Customer)1 NavigationHandler (javax.faces.application.NavigationHandler)1 Event (javax.portlet.Event)1 BridgeEventHandler (javax.portlet.faces.BridgeEventHandler)1 BridgeException (javax.portlet.faces.BridgeException)1