Search in sources :

Example 1 with BridgeEventHandler

use of javax.portlet.faces.BridgeEventHandler 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 BridgeEventHandler

use of javax.portlet.faces.BridgeEventHandler in project liferay-faces-bridge-impl by liferay.

the class InitMethodTestPortlet method init.

public void init(PortletConfig portletConfig) throws PortletException {
    super.init(portletConfig);
    boolean bTestPassed = true;
    StringBuilder msg = new StringBuilder();
    // getBridgeClassName test
    if (bGetBridgeClassNameCalled) {
        msg.append("getBridgeClassName() called.");
    } else {
        bTestPassed = false;
        msg.append("getBridgeClassName() not called.");
    }
    // to those returned from getExcludedRequestAttributes.
    if (bGetExcludedRequestAttributesCalled) {
        msg.append("  getExcludedRequestAttributes() called.");
    } else {
        bTestPassed = false;
        msg.append("  getExcludedRequestAttributes() not called.");
    }
    List<String> attrs = (List<String>) getPortletContext().getAttribute("javax.portlet.faces." + getPortletName() + ".excludedRequestAttributes");
    for (String expectedAttr : mExcludedRequestAttrs) {
        if (!attrs.contains(expectedAttr)) {
            bTestPassed = false;
            msg.append("  Missing excluded request attribute ").append(expectedAttr).append(".");
        }
    }
    // to the same value as isPreserveActionParameters.
    if (bIsPreserveActionParametersCalled) {
        msg.append("  isPreserveActionParameters() called.");
    } else {
        bTestPassed = false;
        msg.append("  isPreserveActionParameters() not called.");
    }
    Boolean contextValue = (Boolean) getPortletContext().getAttribute("javax.portlet.faces." + getPortletName() + ".preserveActionParams");
    if (!Boolean.valueOf(bIsPreserveActionParametersResult).equals(contextValue)) {
        msg.append("  Value of the preserveActionParams context attribute is ").append(contextValue).append(", expected value is ").append(Boolean.valueOf(bIsPreserveActionParametersResult)).append(".");
        bTestPassed = false;
    }
    // getDefaultViewIdMap.
    if (bGetDefaultViewIdMapCalled) {
        msg.append("  getDefaultViewIdMapCalled() called.");
    } else {
        msg.append("  getDefaultViewIdMapCalled() not called.");
        bTestPassed = false;
    }
    Map viewIdMapAttr = (Map) getPortletContext().getAttribute("javax.portlet.faces." + getPortletName() + ".defaultViewIdMap");
    if (!mDefaultViewIdMap.isEmpty()) {
        if (viewIdMapAttr == null) {
            msg.append("  Portlet context attribute javax.portlet.faces.").append(getPortletName()).append(".defaultViewIdMap has not been set.");
        } else {
            for (String mode : mDefaultViewIdMap.keySet()) {
                if (viewIdMapAttr.get(mode) == null) {
                    bTestPassed = false;
                    msg.append("  Mode, ").append(mode).append(", has been set in the map returned by getDefaultViewIdMap but has not been set in javax.portlet.faces.").append(getPortletName()).append(".defaultViewIdMap");
                }
            }
        }
    } else {
        if (viewIdMapAttr != null) {
            msg.append("  Portlet context attribute javax.portlet.faces.").append(getPortletName()).append(".defaultViewIdMap has been set while the getDefaultViewIdMap returns null.");
            bTestPassed = false;
        }
    }
    // to the same value as mEventHandler.
    if (bGetBridgeEventHandlerCalled) {
        msg.append("  getBridgeEventHandler() called.");
    } else {
        bTestPassed = false;
        msg.append("  getBridgeEventHandler() not called.");
    }
    BridgeEventHandler eventHandler = (BridgeEventHandler) getPortletContext().getAttribute("javax.portlet.faces." + getPortletName() + ".bridgeEventHandler");
    if (((eventHandler == null) && (mEventHandler != null)) || ((mEventHandler == null) && (eventHandler != null)) || (!mEventHandler.equals(eventHandler))) {
        msg.append("  Value of the bridgeEventHandler context attribute is ").append(eventHandler).append(", expected value is ").append(mEventHandler).append(".");
        bTestPassed = false;
    }
    // to the same value as mPRPHandler.
    if (bGetBridgePRPHandlerCalled) {
        msg.append("  getBridgePublicRenderParameterHandler() called.");
    } else {
        bTestPassed = false;
        msg.append("  getBridgePublicRenderParameterHandler() not called.");
    }
    BridgePublicRenderParameterHandler prpHandler = (BridgePublicRenderParameterHandler) getPortletContext().getAttribute("javax.portlet.faces." + getPortletName() + ".bridgePublicRenderParameterHandler");
    if (((prpHandler == null) && (mPRPhandler != null)) || ((mPRPhandler == null) && (prpHandler != null)) || (!mPRPhandler.equals(prpHandler))) {
        msg.append("  Value of the bridgePublicRenderParameterHandler context attribute is ").append(prpHandler).append(", expected value is ").append(mPRPhandler).append(".");
        bTestPassed = false;
    }
    // to the same value as mDefaultRenderKitId.
    if (bGetDefaultRenderKitIdCalled) {
        msg.append("  getDefaultRenderKitId() called.");
    } else {
        bTestPassed = false;
        msg.append("  getDefaultRenderKitId() not called.");
    }
    String defaultRenderKitId = (String) getPortletContext().getAttribute("javax.portlet.faces." + getPortletName() + ".defaultRenderKitId");
    if (((defaultRenderKitId == null) && (mDefaultRenderKitId != null)) || ((mDefaultRenderKitId == null) && (defaultRenderKitId != null)) || (!mDefaultRenderKitId.equals(defaultRenderKitId))) {
        msg.append("  Value of the defaultRenderKitId context attribute is ").append(defaultRenderKitId).append(", expected value is ").append(mDefaultRenderKitId).append(".");
        bTestPassed = false;
    }
    if (bTestPassed) {
        getPortletContext().setAttribute(TEST_PASS_PREFIX + getPortletName(), msg.toString());
    } else {
        getPortletContext().setAttribute(TEST_FAIL_PREFIX + getPortletName(), msg.toString());
    }
}
Also used : BridgeEventHandler(javax.portlet.faces.BridgeEventHandler) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) BridgePublicRenderParameterHandler(javax.portlet.faces.BridgePublicRenderParameterHandler)

Example 3 with BridgeEventHandler

use of javax.portlet.faces.BridgeEventHandler in project liferay-faces-bridge-impl by liferay.

the class BridgeEventHandlerFactoryImpl method getBridgeEventHandler.

@Override
public BridgeEventHandler getBridgeEventHandler(PortletConfig portletConfig) {
    BridgeEventHandler bridgeEventHandler = null;
    // TCK: initMethodTest
    String bridgeEventHandlerClass = portletConfig.getInitParameter("javax.portlet.faces.bridgeEventHandler");
    if (bridgeEventHandlerClass != null) {
        try {
            Class<?> clazz = TCCLUtil.loadClassFromContext(getClass(), bridgeEventHandlerClass);
            bridgeEventHandler = (BridgeEventHandler) clazz.newInstance();
        } catch (Exception e) {
            logger.error(e);
        }
    }
    return bridgeEventHandler;
}
Also used : BridgeEventHandler(javax.portlet.faces.BridgeEventHandler)

Aggregations

BridgeEventHandler (javax.portlet.faces.BridgeEventHandler)3 EventPayloadWrapper (com.liferay.faces.bridge.event.EventPayloadWrapper)1 BridgeRequestScope (com.liferay.faces.bridge.scope.internal.BridgeRequestScope)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 NavigationHandler (javax.faces.application.NavigationHandler)1 Event (javax.portlet.Event)1 BridgeException (javax.portlet.faces.BridgeException)1 BridgePublicRenderParameterHandler (javax.portlet.faces.BridgePublicRenderParameterHandler)1 EventNavigationResult (javax.portlet.faces.event.EventNavigationResult)1