Search in sources :

Example 1 with BridgeDefaultViewNotSpecifiedException

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

the class ManualBridgeInvokePortlet method renderView.

@Override
public void renderView(RenderRequest renderRequest, MimeResponse mimeResponse) throws PortletException, IOException {
    if (getTestName().equals(EXCEPTIONTHROWN_NODEFAULTVIEWID_TEST)) {
        Bridge bridge = super.getFacesBridge(renderRequest, mimeResponse);
        try {
            doBridgeFacesRequest(bridge, renderRequest, mimeResponse);
        } catch (BridgeDefaultViewNotSpecifiedException e) {
            outputTestResult(renderRequest, mimeResponse, Boolean.TRUE, "Correctly threw BridgeDefaultViewNotSpecifiedException when no default defined.");
        } catch (Exception e) {
            outputTestResult(renderRequest, mimeResponse, Boolean.FALSE, "Didn't throw BridgeDefaultViewNotSpecifiedException when no default defined.");
        }
    } else if (getTestName().equals(BRIDGESETSCONTENTTYPE_TEST)) {
        // Invoke the bridge directly and do not set the contentType (as is normally done in the outputTestResult
        // method below). See the comments in bridgeSetsContentTypeTest for more information as to how the test
        // is designed.
        Bridge bridge = super.getFacesBridge(renderRequest, mimeResponse);
        doBridgeFacesRequest(bridge, renderRequest, mimeResponse);
    } else if (getTestName().equals(VIEWIDWITHPARAM_TEST)) {
        renderRequest.setAttribute(Bridge.VIEW_ID, "/tests/singleRequestTest.xhtml?param1=testValue");
        dispatchToView(renderRequest, mimeResponse);
    } else if (getTestName().equals(FACESCONTEXTRELEASED_ACTION_TEST) || getTestName().equals(PORTLETPHASEREMOVED_ACTION_TEST) || getTestName().equals(FACESCONTEXTRELEASED_EVENT_TEST) || getTestName().equals(PORTLETPHASEREMOVED_EVENT_TEST)) {
        // Output in the Test method fort his test
        dispatchToView(renderRequest, mimeResponse);
    } else if (getTestName().equals(FACESCONTEXTRELEASED_RENDER_TEST)) {
        dispatchToView(renderRequest, mimeResponse);
        if (renderRequest.getPortletSession(true).getAttribute("org.apache.portlet.faces.tck.facesContextReleased") != null) {
            outputTestResult(renderRequest, mimeResponse, Boolean.TRUE, "Correctly release FacesContext at end of render.");
            renderRequest.getPortletSession().removeAttribute("org.apache.portlet.faces.tck.facesContextReleased");
        } else {
            outputTestResult(renderRequest, mimeResponse, Boolean.FALSE, "FacesContext not release at end of render.");
        }
    } else if (getTestName().equals(PORTLETPHASEREMOVED_RENDER_TEST)) {
        dispatchToView(renderRequest, mimeResponse);
        if (renderRequest.getAttribute(Bridge.PORTLET_LIFECYCLE_PHASE) == null) {
            outputTestResult(renderRequest, mimeResponse, Boolean.TRUE, "Correctly removed Portlet Phase attribute at end of render.");
        } else {
            outputTestResult(renderRequest, mimeResponse, Boolean.FALSE, "Didn't remove Portlet Phase attribute at end of render.");
        }
    } else {
        dispatchToView(renderRequest, mimeResponse);
    }
}
Also used : BridgeDefaultViewNotSpecifiedException(javax.portlet.faces.BridgeDefaultViewNotSpecifiedException) Bridge(javax.portlet.faces.Bridge) BridgeDefaultViewNotSpecifiedException(javax.portlet.faces.BridgeDefaultViewNotSpecifiedException) PortletSecurityException(javax.portlet.PortletSecurityException) IOException(java.io.IOException) PortletException(javax.portlet.PortletException)

Example 2 with BridgeDefaultViewNotSpecifiedException

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

the class ExternalContextImpl method getFacesViewIdAndQueryString.

/**
 * <p>This method returns the target view (and optional query string) as described in section 5.2.3 of the Bridge
 * Spec titled "Determining the Target View".</p>
 *
 * <p>Try#1: Get the viewId from the {@link Bridge#VIEW_ID} (javax.portlet.faces.viewId) request attribute. As
 * described in sections 3.4 and 4.2.5 of the bridge spec, this attribute is set by the {@link GenericFacesPortlet}
 * when it encounters the {@link Bridge#FACES_VIEW_ID_PARAMETER} request parameter.</p>
 *
 * <p>Try#2: Get the viewId from the {@link Bridge#VIEW_PATH} (javax.portlet.faces.viewPath) request attribute. As
 * described in sections 3.4 and 4.2.5 of the bridge spec, this attribute is set by the {@link GenericFacesPortlet}
 * when it encounters the {@link Bridge#FACES_VIEW_PATH_PARAMETER} request parameter. If the viewId cannot be
 * determined, then {@link BridgeInvalidViewPathException} is thrown.</p>
 *
 * <p>Try#3: Get the viewId from a prior render-redirect (if one has occurred).</p>
 *
 * <p>Try#4: Get the viewId from a request parameter, the name of which is dynamic depending on the {@link
 * Bridge.PortletPhase}.</p>
 *
 * <p>Try#5:Get the viewId from the init-param value in the portlet.xml descriptor according the current {@link
 * PortletMode}.</p>
 *
 * @throws  BridgeDefaultViewNotSpecifiedException  when the default view is not specified in the
 *                                                  WEB-INF/portlet.xml descriptor.
 * @throws  BridgeInvalidViewPathException          when the {@link Bridge#VIEW_PATH} request attribute contains an
 *                                                  invalid path such that the target view cannot be determined.
 */
protected String getFacesViewIdAndQueryString() throws BridgeDefaultViewNotSpecifiedException, BridgeInvalidViewPathException {
    if (viewIdAndQueryString == null) {
        // Try#1: Get the viewId the "javax.portlet.faces.viewId" request attribute.
        if (PortletConfigParam.ViewIdParameterEnabled.getBooleanValue(portletConfig)) {
            viewIdAndQueryString = getFacesViewIdRequestAttribute(Bridge.VIEW_ID);
        }
        if (viewIdAndQueryString == null) {
            // Try#2: Get the viewId from the "javax.portlet.faces.viewPath" request attribute.
            String viewPath = null;
            if (PortletConfigParam.ViewPathParameterEnabled.getBooleanValue(portletConfig)) {
                viewPath = getFacesViewIdRequestAttribute(Bridge.VIEW_PATH);
            }
            if (viewPath != null) {
                // If present, remove the query string from the specified viewPath.
                int pos = viewPath.indexOf("?");
                if (pos > 0) {
                    viewPath = viewPath.substring(0, pos);
                }
                // If present, remove everything up to (and including) the context path from the viewPath.
                String contextPath = portletRequest.getContextPath();
                pos = viewPath.indexOf(contextPath);
                if (pos >= 0) {
                    viewPath = viewPath.substring(pos + contextPath.length());
                }
                if (!viewPath.startsWith("/")) {
                    viewPath = "/" + viewPath;
                }
                viewIdAndQueryString = getFacesViewIdFromPath(viewPath);
                if (viewIdAndQueryString == null) {
                    throw new BridgeInvalidViewPathException();
                }
            }
            if (viewIdAndQueryString == null) {
                // Try #3: Get the viewId from a prior render-redirect (if one has occurred). Note that this logic
                // depends on the BridgePhaseRenderImpl calling the setRenderRedirectURL(BridgeRedirectURL) method
                // on this class instance when a render-redirect takes place.
                String renderRedirectViewId = (String) portletRequest.getAttribute(BridgeExt.RENDER_REDIRECT_VIEW_ID);
                if (renderRedirectViewId != null) {
                    viewIdAndQueryString = renderRedirectViewId;
                }
                if (viewIdAndQueryString == null) {
                    // Try#4: Get the viewId from a request parameter, the name of which is dynamic depending on
                    // the portlet phase.
                    String requestParameterName = null;
                    if ((portletPhase == Bridge.PortletPhase.RESOURCE_PHASE) && PortletConfigParam.ViewIdResourceParameterEnabled.getBooleanValue(portletConfig)) {
                        requestParameterName = bridgeConfig.getViewIdResourceParameterName();
                    } else if (PortletConfigParam.ViewIdRenderParameterEnabled.getBooleanValue(portletConfig)) {
                        requestParameterName = bridgeConfig.getViewIdRenderParameterName();
                    }
                    if (requestParameterName != null) {
                        viewIdAndQueryString = getFacesViewIdRequestParameter(requestParameterName);
                    }
                    if (viewIdAndQueryString == null) {
                        // Try#5: Get the viewId from the init-param value in the portlet.xml descriptor according
                        // to the current portlet mode.
                        PortletMode currentPortletMode = portletRequest.getPortletMode();
                        // a JSF 2 resource URL.
                        if (PortletMode.UNDEFINED.equals(currentPortletMode)) {
                            logger.debug("Unable to get the default view for portletMode=undefined");
                        } else // Otherwise, determine the default view according to the portlet mode. If it can't be
                        // determined then throw BridgeDefaultViewNotSpecifiedException according to Section 5.2.3
                        // of the FacesBridge Spec.
                        {
                            viewIdAndQueryString = getDefaultViewIdMap(portletConfig).get(currentPortletMode.toString());
                            logger.debug("portlet.xml viewId=[{0}] portletMode=[{1}]", viewIdAndQueryString, currentPortletMode);
                            if (viewIdAndQueryString == null) {
                                throw new BridgeDefaultViewNotSpecifiedException();
                            }
                        }
                    } else {
                        logger.debug("request parameter {0}=[{1}]", requestParameterName, viewIdAndQueryString);
                    }
                } else {
                    logger.debug("redirect viewId=[{0}]", viewIdAndQueryString);
                }
            }
        } else {
            logger.debug("javax.portlet.faces.viewId=[{0}]", viewIdAndQueryString);
        }
    }
    if ((viewIdAndQueryString != null) && !viewIdAndQueryString.startsWith("/")) {
        viewIdAndQueryString = "/" + viewIdAndQueryString;
    }
    return viewIdAndQueryString;
}
Also used : BridgeInvalidViewPathException(javax.portlet.faces.BridgeInvalidViewPathException) BridgeDefaultViewNotSpecifiedException(javax.portlet.faces.BridgeDefaultViewNotSpecifiedException) PortletMode(javax.portlet.PortletMode)

Aggregations

BridgeDefaultViewNotSpecifiedException (javax.portlet.faces.BridgeDefaultViewNotSpecifiedException)2 IOException (java.io.IOException)1 PortletException (javax.portlet.PortletException)1 PortletMode (javax.portlet.PortletMode)1 PortletSecurityException (javax.portlet.PortletSecurityException)1 Bridge (javax.portlet.faces.Bridge)1 BridgeInvalidViewPathException (javax.portlet.faces.BridgeInvalidViewPathException)1