Search in sources :

Example 26 with StateAwareResponse

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

the class Tests method eventNoHandlerPRPPreservedTest.

// Test is MultiRequest -- Render/Action
// Test # -- 5.58
@BridgeTest(test = "eventNoHandlerPRPPreservedTest")
public String eventNoHandlerPRPPreservedTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    // are explicitly excluded -- test for presence/absence in render
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
        // Set the value into the model underneath the public render parameter
        externalContext.getRequestMap().put("modelPRP", testBean.getTestName());
        // Create and raise the event
        StateAwareResponse stateAwareResponse = (StateAwareResponse) externalContext.getResponse();
        stateAwareResponse.setEvent(new QName(Constants.EVENT_QNAME, Constants.EVENT_NAME), testBean.getTestName());
        // action Navigation result
        return "eventNoHandlerPRPPreservedTest";
    } else {
        testBean.setTestComplete(true);
        // ensure that both the public render paramter and the model are there and have the same value
        RenderRequest request = (RenderRequest) externalContext.getRequest();
        String[] prpArray = request.getPublicParameterMap().get("testPRP");
        String modelPRP = (String) externalContext.getRequestMap().get("modelPRP");
        if (prpArray == null) {
            testBean.setTestResult(false, "event raised without a registered handler didn't carry forward the public render parameter.");
            return Constants.TEST_FAILED;
        } else if (modelPRP == null) {
            testBean.setTestResult(false, "event raised without a registered handler didn't update the model from the passed public render parameter.");
            return Constants.TEST_FAILED;
        } else if (!modelPRP.equals(prpArray[0])) {
            testBean.setTestResult(false, "event raised without a registered handler:  passed public render parameter value doesn't match underlying one.");
            return Constants.TEST_FAILED;
        } else if (!modelPRP.equals(testBean.getTestName())) {
            testBean.setTestResult(false, "event raised without a registered handler:  public render parameter didn't contain expected value.  PRP value: " + modelPRP + " but expected: " + testBean.getTestName());
            return Constants.TEST_FAILED;
        } else {
            testBean.setTestResult(true, "event raised without a registered handler worked correctly as the public render parameter was maintained.");
            return Constants.TEST_SUCCESS;
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) StateAwareResponse(javax.portlet.StateAwareResponse) ExternalContext(javax.faces.context.ExternalContext) QName(javax.xml.namespace.QName) RenderRequest(javax.portlet.RenderRequest) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 27 with StateAwareResponse

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

the class Tests method eventScopeNotRestoredRedirectTest.

// Test is MultiRequest -- Render/Action
// Test # -- 5.49
@BridgeTest(test = "eventScopeNotRestoredRedirectTest")
public String eventScopeNotRestoredRedirectTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    // are explicitly excluded -- test for presence/absence in render
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
        // Clear settings from previous run of the test
        externalContext.getSessionMap().put(Ch5TestEventHandler.EVENT_RECEIVED, null);
        externalContext.getSessionMap().put(Ch5TestEventHandler.EVENT_TEST_FAILED, null);
        // Place a request attr in scope so we can make sure its not there later
        externalContext.getRequestMap().put(Ch5TestEventHandler.EVENTATTR, testBean.getTestName());
        // Create and raise the event
        StateAwareResponse stateAwareResponse = (StateAwareResponse) externalContext.getResponse();
        stateAwareResponse.setEvent(new QName(Constants.EVENT_QNAME, Constants.EVENT_NAME), testBean.getTestName());
        // action Navigation result
        return "eventScopeNotRestoredRedirectTest";
    } else {
        testBean.setTestComplete(true);
        // Values set by portlet at end of action
        Event event = (Event) externalContext.getSessionMap().get(Ch5TestEventHandler.EVENT_RECEIVED);
        String failedMsg = (String) externalContext.getSessionMap().get(Ch5TestEventHandler.EVENT_TEST_FAILED);
        String payload = (String) externalContext.getRequestMap().get(Ch5TestEventHandler.EVENTATTR);
        if (event == null) {
            testBean.setTestResult(false, "Raised event wasn't received.");
            return Constants.TEST_FAILED;
        } else if (failedMsg != null) {
            testBean.setTestResult(false, failedMsg);
            return Constants.TEST_FAILED;
        } else if (payload != null) {
            testBean.setTestResult(false, "Event navigation issued a redirect but the request scope was preserved.");
            return Constants.TEST_FAILED;
        } else {
            testBean.setTestResult(true, "Request scope not preserved after event navigation issued a redirect.");
            return Constants.TEST_SUCCESS;
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) StateAwareResponse(javax.portlet.StateAwareResponse) ExternalContext(javax.faces.context.ExternalContext) QName(javax.xml.namespace.QName) ActionEvent(javax.faces.event.ActionEvent) PhaseEvent(javax.faces.event.PhaseEvent) Event(javax.portlet.Event) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 28 with StateAwareResponse

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

the class Tests method eventScopeRestoredTest.

// Test is MultiRequest -- Render/Action
// Test # -- 5.48
@BridgeTest(test = "eventScopeRestoredTest")
public String eventScopeRestoredTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    // are explicitly excluded -- test for presence/absence in render
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
        // Clear settings from previous run of the test: Done here because this render doesn't happen in scope so
        // second rendition doesn't keep the test result -- rather rerenders
        externalContext.getSessionMap().put(Ch5TestEventHandler.EVENT_RECEIVED, null);
        externalContext.getSessionMap().put(Ch5TestEventHandler.EVENT_TEST_FAILED, null);
        // Place a request attr in scope so we can make sure its still there later
        externalContext.getRequestMap().put(Ch5TestEventHandler.EVENTATTR, testBean.getTestName());
        // Create and raise the event
        StateAwareResponse stateAwareResponse = (StateAwareResponse) externalContext.getResponse();
        stateAwareResponse.setEvent(new QName(Constants.EVENT_QNAME, Constants.EVENT_NAME), testBean.getTestName());
        // action Navigation result
        return "eventScopeRestoredTest";
    } else {
        testBean.setTestComplete(true);
        // Values set by portlet at end of action
        Event event = (Event) externalContext.getSessionMap().get(Ch5TestEventHandler.EVENT_RECEIVED);
        String failedMsg = (String) externalContext.getSessionMap().get(Ch5TestEventHandler.EVENT_TEST_FAILED);
        String payload = (String) externalContext.getRequestMap().get(Ch5TestEventHandler.EVENTATTR);
        if (event == null) {
            testBean.setTestResult(false, "Raised event wasn't received.");
            return Constants.TEST_FAILED;
        } else if (failedMsg != null) {
            testBean.setTestResult(false, failedMsg);
            return Constants.TEST_FAILED;
        } else if ((payload == null) || !payload.equals(testBean.getTestName())) {
            testBean.setTestResult(false, "Event received and request scope restored but that scope wasn't carried forward into the render");
            return Constants.TEST_FAILED;
        } else {
            testBean.setTestResult(true, "Event received and request scope restored.");
            return Constants.TEST_SUCCESS;
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) StateAwareResponse(javax.portlet.StateAwareResponse) ExternalContext(javax.faces.context.ExternalContext) QName(javax.xml.namespace.QName) ActionEvent(javax.faces.event.ActionEvent) PhaseEvent(javax.faces.event.PhaseEvent) Event(javax.portlet.Event) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 29 with StateAwareResponse

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

the class Tests method portletPhaseRemovedEventTest.

// Test is MultiRequest -- Render/Action
// Test #5.60
@BridgeTest(test = "portletPhaseRemovedEventTest")
public String portletPhaseRemovedEventTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    // are explicitly excluded -- test for presence/absence in render
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
        StateAwareResponse stateAwareResponse = (StateAwareResponse) externalContext.getResponse();
        stateAwareResponse.setEvent(new QName(Constants.EVENT_QNAME, Constants.EVENT_NAME), testBean.getTestName());
        // action Navigation result
        return "portletPhaseRemovedEventTest";
    } else {
        testBean.setTestComplete(true);
        // Values set by portlet at end of action
        boolean result = ((Boolean) externalContext.getSessionMap().get("org.apache.portlet.faces.tck.testResult")).booleanValue();
        testBean.setTestResult(result, (String) externalContext.getSessionMap().get("org.apache.portlet.faces.tck.testDetail"));
        if (result) {
            return Constants.TEST_SUCCESS;
        } else {
            return Constants.TEST_FAILED;
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) StateAwareResponse(javax.portlet.StateAwareResponse) ExternalContext(javax.faces.context.ExternalContext) QName(javax.xml.namespace.QName) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 30 with StateAwareResponse

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

the class BridgeNavigationHandlerImpl method handleNavigation.

@Override
public void handleNavigation(FacesContext facesContext, String fromAction, String outcome) {
    logger.debug("fromAction=[{0}] outcome=[{1}]", fromAction, outcome);
    String queryString = null;
    UIViewRoot uiViewRoot = facesContext.getViewRoot();
    String viewId = uiViewRoot.getViewId();
    if (viewId != null) {
        int pos = viewId.indexOf("?");
        if (pos > 0) {
            queryString = viewId.substring(pos);
            viewId = viewId.substring(0, pos);
            uiViewRoot.setViewId(viewId);
        }
    }
    NavigationCase navigationCase = getNavigationCase(facesContext, fromAction, outcome);
    // Ask the wrapped NavigationHandler to perform the navigation.
    getWrappedNavigationHandler().handleNavigation(facesContext, fromAction, outcome);
    if (queryString != null) {
        uiViewRoot.setViewId(viewId.concat(queryString));
    }
    if (navigationCase != null) {
        // Hack for http://jira.icesoft.org/browse/ICE-7996
        Iterator<FacesMessage> itr = facesContext.getMessages();
        while (itr.hasNext()) {
            FacesMessage facesMessage = itr.next();
            if (facesMessage.getDetail().contains("Unable to find matching navigation case")) {
                logger.warn("Removed bogus FacesMessage caused by http://jira.icesoft.org/browse/ICE-7996");
                itr.remove();
            }
        }
        // ExternalContext.redirect(String) directly from their application.
        if (!navigationCase.isRedirect()) {
            String toViewId = navigationCase.getToViewId(facesContext);
            if (toViewId != null) {
                ExternalContext externalContext = facesContext.getExternalContext();
                PortletResponse portletResponse = (PortletResponse) externalContext.getResponse();
                if (portletResponse instanceof StateAwareResponse) {
                    PortletContext portletContext = (PortletContext) externalContext.getContext();
                    BridgeURLFactory bridgeURLFactory = (BridgeURLFactory) BridgeFactoryFinder.getFactory(portletContext, BridgeURLFactory.class);
                    try {
                        BridgeURL bridgeActionURL = bridgeURLFactory.getBridgeActionURL(facesContext, toViewId);
                        BridgeNavigationCase bridgeNavigationCase = new BridgeNavigationCaseImpl(navigationCase);
                        String portletMode = bridgeNavigationCase.getPortletMode();
                        if (portletMode != null) {
                            bridgeActionURL.setParameter(Bridge.PORTLET_MODE_PARAMETER, portletMode);
                        }
                        String windowState = bridgeNavigationCase.getWindowState();
                        if (windowState != null) {
                            bridgeActionURL.setParameter(Bridge.PORTLET_WINDOWSTATE_PARAMETER, windowState);
                        }
                        PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
                        BridgeNavigationUtil.navigate(portletRequest, (StateAwareResponse) portletResponse, bridgeActionURL.getParameterMap());
                    } catch (Exception e) {
                        logger.error(e.getMessage());
                    }
                }
            }
        }
    }
}
Also used : PortletResponse(javax.portlet.PortletResponse) StateAwareResponse(javax.portlet.StateAwareResponse) BridgeURLFactory(javax.portlet.faces.BridgeURLFactory) PortletRequest(javax.portlet.PortletRequest) NavigationCase(javax.faces.application.NavigationCase) ExternalContext(javax.faces.context.ExternalContext) PortletContext(javax.portlet.PortletContext) UIViewRoot(javax.faces.component.UIViewRoot) FacesMessage(javax.faces.application.FacesMessage) BridgeURL(javax.portlet.faces.BridgeURL)

Aggregations

StateAwareResponse (javax.portlet.StateAwareResponse)34 ExternalContext (javax.faces.context.ExternalContext)29 FacesContext (javax.faces.context.FacesContext)29 QName (javax.xml.namespace.QName)27 BridgeTest (com.liferay.faces.bridge.tck.annotation.BridgeTest)26 PortletRequest (javax.portlet.PortletRequest)9 ActionEvent (javax.faces.event.ActionEvent)3 PhaseEvent (javax.faces.event.PhaseEvent)3 Event (javax.portlet.Event)3 ELContext (javax.el.ELContext)2 ELResolver (javax.el.ELResolver)2 UIViewRoot (javax.faces.component.UIViewRoot)2 PortletMode (javax.portlet.PortletMode)2 PortletSession (javax.portlet.PortletSession)2 WindowState (javax.portlet.WindowState)2 Bridge (javax.portlet.faces.Bridge)2 BridgeURL (javax.portlet.faces.BridgeURL)2 BridgePortalContext (com.liferay.faces.bridge.context.BridgePortalContext)1 BridgeURI (com.liferay.faces.bridge.internal.BridgeURI)1 FacesURLEncoder (com.liferay.faces.util.render.FacesURLEncoder)1