Search in sources :

Example 1 with BridgeURLFactory

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

the class FormRendererPrimeFacesImpl method encodeBegin.

@Override
public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    // "javax.faces.encodedURL" hidden field.
    if ((majorVersion == 3) && (minorVersion < 3) && isMultiPartForm(uiComponent)) {
        boolean hasPrimeFacesAjaxFileUploadChild = false;
        UIComponent childComponent = getChildWithRendererType(uiComponent, RenderKitBridgeImpl.PRIMEFACES_FILE_UPLOAD_RENDERER_TYPE);
        if (childComponent != null) {
            if (!isSimpleMode(uiComponent)) {
                hasPrimeFacesAjaxFileUploadChild = true;
                facesContext.getAttributes().put(AJAX_FILE_UPLOAD, Boolean.TRUE);
            }
        }
        // Continue encoding with the wrapped FormRenderer. When it comes time to call
        // ExternalContext.encodeActionURL(String), the bridge will check for the
        // PrimeFacesFileUpload.AJAX_FILE_UPLOAD attribute. If found, then it will return a PartialActionURL
        // suitable for Ajax requests.
        super.encodeBegin(facesContext, uiComponent);
        if (hasPrimeFacesAjaxFileUploadChild) {
            facesContext.getAttributes().remove(AJAX_FILE_UPLOAD);
        }
    } else // the ACTION_PHASE of the portlet lifecycle.
    if (hasNonAjaxActionListener(uiComponent)) {
        ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
        String viewId = facesContext.getViewRoot().getViewId();
        String facesActionURL = viewHandler.getActionURL(facesContext, viewId);
        ExternalContext externalContext = facesContext.getExternalContext();
        PortletContext portletContext = (PortletContext) externalContext.getContext();
        BridgeURLFactory bridgeURLFactory = (BridgeURLFactory) BridgeFactoryFinder.getFactory(portletContext, BridgeURLFactory.class);
        try {
            BridgeURL partialActionURL = bridgeURLFactory.getBridgePartialActionURL(facesContext, facesActionURL);
            partialActionURL.removeParameter(Bridge.FACES_AJAX_PARAMETER);
            partialActionURL.setParameter(BridgeExt.FACES_EXPORT_COMPONENT_PARAMETER, "true");
            String nonAjaxPartialActionURL = partialActionURL.toString();
            ResponseWriter responseWriter = facesContext.getResponseWriter();
            ResponseWriter primeFacesResponseWriter = new ResponseWriterPrimeFacesBodyImpl(responseWriter, nonAjaxPartialActionURL);
            facesContext.setResponseWriter(primeFacesResponseWriter);
            super.encodeBegin(facesContext, uiComponent);
            facesContext.setResponseWriter(responseWriter);
        } catch (BridgeException e) {
            logger.error(e);
        }
    } else // Otherwise, delegate encoding to the wrapped renderer.
    {
        super.encodeBegin(facesContext, uiComponent);
    }
}
Also used : BridgeException(javax.portlet.faces.BridgeException) BridgeURLFactory(javax.portlet.faces.BridgeURLFactory) ResponseWriter(javax.faces.context.ResponseWriter) ViewHandler(javax.faces.application.ViewHandler) ExternalContext(javax.faces.context.ExternalContext) UIComponent(javax.faces.component.UIComponent) PortletContext(javax.portlet.PortletContext) BridgeURL(javax.portlet.faces.BridgeURL)

Example 2 with BridgeURLFactory

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

ExternalContext (javax.faces.context.ExternalContext)2 PortletContext (javax.portlet.PortletContext)2 BridgeURL (javax.portlet.faces.BridgeURL)2 BridgeURLFactory (javax.portlet.faces.BridgeURLFactory)2 FacesMessage (javax.faces.application.FacesMessage)1 NavigationCase (javax.faces.application.NavigationCase)1 ViewHandler (javax.faces.application.ViewHandler)1 UIComponent (javax.faces.component.UIComponent)1 UIViewRoot (javax.faces.component.UIViewRoot)1 ResponseWriter (javax.faces.context.ResponseWriter)1 PortletRequest (javax.portlet.PortletRequest)1 PortletResponse (javax.portlet.PortletResponse)1 StateAwareResponse (javax.portlet.StateAwareResponse)1 BridgeException (javax.portlet.faces.BridgeException)1