Package com.liferay.faces.bridge.context.url

Examples of com.liferay.faces.bridge.context.url.BridgeRedirectURL


    if (url != null) {
      logger.debug("redirect url=[{0}]", url);

      String currentFacesViewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();

      BridgeRedirectURL bridgeRedirectURL = bridgeURLFactory.getBridgeRedirectURL(url, null, currentFacesViewId,
          this);

      // If currently executing the ACTION_PHASE, EVENT_PHASE, or RENDER_PHASE of the portlet lifecycle, then
      if ((portletPhase == Bridge.PortletPhase.ACTION_PHASE) ||
          (portletPhase == Bridge.PortletPhase.EVENT_PHASE) ||
          (portletPhase == Bridge.PortletPhase.RENDER_PHASE)) {

        // If the specified URL starts with a "#" character, is external to this application, or has a
        // "javax.portlet.faces.DirectLink" parameter value of "true", then
        if ((portletPhase == Bridge.PortletPhase.ACTION_PHASE) &&
            (url.startsWith(StringPool.POUND) || bridgeRedirectURL.isExternal() ||
              BooleanHelper.isTrueToken(bridgeRedirectURL.getParameter(Bridge.DIRECT_LINK)))) {

          bridgeRequestScope.setRedirectOccurred(true);

          // TCK NOTE: The TCK does not appear to have a test that invokes this condition.
          portletContainer.redirect(bridgeRedirectURL.toString());
        }

        // Otherwise,
        else {

          FacesContext facesContext = FacesContext.getCurrentInstance();
          String newViewId = bridgeRedirectURL.getContextRelativePath();

          // If running in the ACTION_PHASE of the portlet lifecycle, then
          if (portletPhase == Bridge.PortletPhase.ACTION_PHASE) {

            // Update the PartialViewContext.
            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.
            getBridgeRequestScope().setRedirectOccurred(true);

            // Redirect to the targeted view.
            bridgeRedirectURL.setParameter(Bridge.VIEW_ID, newViewId);

            PortletURL redirectURL = portletContainer.createRedirectURL(bridgeRedirectURL.toString(), null);
            portletContainer.redirect(redirectURL.toString());
          }

          // Otherwise, if running in the EVENT_PHASE of the portlet lifecycle, then simply navigate to the
          // target view since it is not possible to redirect during the EVENT_PHASE.
          else if (portletPhase == Bridge.PortletPhase.EVENT_PHASE) {

            // TCK NOTE: The TCK will invoke this condition during the
            // TestPage039-requestNoScopeOnRedirectTest and TestPage176-redirectActionTest.
            String oldViewId = facesContext.getViewRoot().getViewId();

            // If redirecting to a different view, then create the target view and place it into the
            // FacesContext.
            if (!oldViewId.equals(newViewId)) {

              ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
              UIViewRoot newViewRoot = viewHandler.createView(facesContext, newViewId);
              facesContext.setViewRoot(newViewRoot);
            }

            // Update the PartialViewContext.
            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.
            getBridgeRequestScope().setRedirectOccurred(true);

            // Apply the PortletMode, WindowState, etc. that may be present in the URL to the response.
            try {
              StateAwareResponse stateAwareResponse = (StateAwareResponse) portletResponse;
              bridgeRedirectURL.applyToResponse(stateAwareResponse);
            }
            catch (PortletModeException e) {
              logger.error(e.getMessage());
            }
            catch (WindowStateException e) {
              logger.error(e.getMessage());
            }
          }

          // Otherwise, if currently executing the RENDER_PHASE of the portlet lifecycle, then
          else if (portletPhase == Bridge.PortletPhase.RENDER_PHASE) {

            // If the specified URL is for a JSF viewId, then prepare for a render-redirect.
            if (bridgeRedirectURL.isFacesViewTarget()) {
              renderRedirect = true;
              renderRedirectURL = bridgeRedirectURL;
            }

            // Otherwise,
            else {

              // If there is a URL parameter specifying a JSF viewId, then prepare for a render-redirect.
              String viewIdRenderParameterName = bridgeConfig.getViewIdRenderParameterName();
              String viewIdRenderParameterValue = bridgeRedirectURL.getParameter(
                  viewIdRenderParameterName);

              if (viewIdRenderParameterValue != null) {

                // TCK TestPage 179: redirectRenderPRP1Test
                renderRedirect = true;
                viewIdRenderParameterValue = URLDecoder.decode(viewIdRenderParameterValue,
                    StringPool.UTF8);
                bridgeRedirectURL = bridgeURLFactory.getBridgeRedirectURL(viewIdRenderParameterValue,
                    null, currentFacesViewId, this);
                renderRedirectURL = bridgeRedirectURL;
              }

              // Otherwise, throw an IllegalStateException according to Section 6.1.3.1 of the Spec.
              else {
                throw new IllegalStateException(
                  "6.1.3.1: Unable to redirect to a non-Faces view during the RENDER_PHASE.");
              }
            }
          }
        }
      }

      // Otherwise, since executing the RESOURCE_PHASE of the portlet lifecycle:
      else {

        // NOTE: The Bridge Spec indicates that the redirect is to be ignored, but JSF 2 has the ability to
        // redirect during Ajax.
        portletContainer.redirect(bridgeRedirectURL.toString());
      }
    }
    else {
      logger.error("redirect url=null");
    }
View Full Code Here

TOP

Related Classes of com.liferay.faces.bridge.context.url.BridgeRedirectURL

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.