Search in sources :

Example 1 with BridgeConfig

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

the class BridgeImpl method doFacesRequest.

@Override
public void doFacesRequest(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws BridgeUninitializedException, BridgeException {
    checkNull(resourceRequest, resourceResponse);
    if (initialized) {
        PortletConfig wrappedPortletConfig = BridgePortletConfigFactory.getPortletConfigInstance(portletConfig);
        BridgeConfig bridgeConfig = BridgeConfigFactory.getBridgeConfigInstance(wrappedPortletConfig);
        BridgePhase bridgePhase = new BridgePhaseResourceImpl(resourceRequest, resourceResponse, wrappedPortletConfig, bridgeConfig);
        bridgePhase.execute();
    } else {
        throw new BridgeUninitializedException();
    }
}
Also used : PortletConfig(javax.portlet.PortletConfig) BridgeConfig(javax.portlet.faces.BridgeConfig) BridgeUninitializedException(javax.portlet.faces.BridgeUninitializedException)

Example 2 with BridgeConfig

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

the class BridgePhaseBaseImpl method init.

protected void init(PortletRequest portletRequest, PortletResponse portletResponse, Bridge.PortletPhase portletPhase) {
    // Save the Bridge.PortletPhase as a request attribute so that it can be picked up by the
    // BridgeRequestAttributeListener.
    portletRequest.setAttribute(Bridge.PORTLET_LIFECYCLE_PHASE, portletPhase);
    // Save the PortletConfig as a request attribute.
    portletRequest.setAttribute(PortletConfig.class.getName(), portletConfig);
    // Save the BridgeConfig as a request attribute.
    portletRequest.setAttribute(BridgeConfig.class.getName(), bridgeConfig);
    // Initialize the bridge request scope.
    initBridgeRequestScope(portletRequest, portletResponse, portletPhase);
    // Save the BridgeRequestScope as a request attribute.
    portletRequest.setAttribute(BridgeRequestScope.class.getName(), bridgeRequestScope);
    // Save the IncongruityContext as a request attribute.
    portletRequest.setAttribute(IncongruityContext.class.getName(), incongruityContext);
    // Save the BridgeContext as a request attribute for legacy versions of ICEfaces.
    setBridgeContextAttribute(portletRequest);
    // Get the FacesContext.
    facesContext = getFacesContext(portletRequest, portletResponse, facesLifecycle);
    // If not set by a previous request, then set the default viewIdHistory for the portlet modes.
    for (String portletMode : PortletModeHelper.PORTLET_MODE_NAMES) {
        String attributeName = Bridge.VIEWID_HISTORY + "." + portletMode;
        PortletSession portletSession = portletRequest.getPortletSession();
        if (portletSession.getAttribute(attributeName) == null) {
            Map<String, String> defaultViewIdMap = ViewUtil.getDefaultViewIdMap(portletConfig);
            portletSession.setAttribute(attributeName, defaultViewIdMap.get(portletMode));
        }
    }
}
Also used : PortletSession(javax.portlet.PortletSession) IncongruityContext(com.liferay.faces.bridge.context.internal.IncongruityContext) PortletConfig(javax.portlet.PortletConfig) BridgeConfig(javax.portlet.faces.BridgeConfig) BridgeRequestScope(com.liferay.faces.bridge.scope.internal.BridgeRequestScope)

Example 3 with BridgeConfig

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

the class ELResolverImpl method resolveVariable.

@Override
protected Object resolveVariable(ELContext elContext, String varName) {
    Object value = null;
    if (varName != null) {
        if (varName.equals(ACTION_REQUEST)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
            if (portletPhase == Bridge.PortletPhase.ACTION_PHASE) {
                value = getPortletRequest(facesContext);
            } else {
                throw new ELException("Unable to get actionRequest during " + portletPhase);
            }
        } else if (varName.equals(ACTION_RESPONSE)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
            if (portletPhase == Bridge.PortletPhase.ACTION_PHASE) {
                value = getPortletResponse(facesContext);
            } else {
                throw new ELException("Unable to get actionResponse during " + portletPhase);
            }
        } else if (varName.equals(BRIDGE_CONFIG) || varName.equals(BRIDGE_CONTEXT) || varName.equals(PORTLET_CONFIG)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            ExternalContext externalContext = facesContext.getExternalContext();
            PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
            BridgeConfig bridgeConfig = RequestMapUtil.getBridgeConfig(portletRequest);
            if (varName.equals(BRIDGE_CONFIG)) {
                value = bridgeConfig;
            } else if (varName.equals(PORTLET_CONFIG)) {
                value = unwrapPortletConfig(RequestMapUtil.getPortletConfig(portletRequest));
            } else {
                value = new LegacyBridgeContext(bridgeConfig);
            }
        } else if (varName.equals(EVENT_REQUEST)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
            if (portletPhase == Bridge.PortletPhase.EVENT_PHASE) {
                value = getPortletRequest(facesContext);
            } else {
                throw new ELException("Unable to get eventRequest during " + portletPhase);
            }
        } else if (varName.equals(EVENT_RESPONSE)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
            if (portletPhase == Bridge.PortletPhase.EVENT_PHASE) {
                value = getPortletResponse(facesContext);
            } else {
                throw new ELException("Unable to get eventResponse during " + portletPhase);
            }
        } else if (varName.equals(FLASH)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            value = getFlash(facesContext);
        } else if (varName.equals(HTTP_SESSION_SCOPE)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            ExternalContext externalContext = facesContext.getExternalContext();
            PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
            PortletSession portletSession = (PortletSession) externalContext.getSession(true);
            PortletConfig portletConfig = RequestMapUtil.getPortletConfig(portletRequest);
            PortletContext portletContext = portletConfig.getPortletContext();
            boolean preferPreDestroy = PortletConfigParam.PreferPreDestroy.getBooleanValue(portletConfig);
            ContextMapFactory contextMapFactory = (ContextMapFactory) BridgeFactoryFinder.getFactory(portletContext, ContextMapFactory.class);
            value = contextMapFactory.getSessionScopeMap(portletContext, portletSession, PortletSession.APPLICATION_SCOPE, preferPreDestroy);
        } else if (varName.equals(MUTABLE_PORTLET_PREFERENCES_VALUES)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            PortletRequest portletRequest = getPortletRequest(facesContext);
            if (portletRequest != null) {
                value = new MutablePreferenceMap(portletRequest.getPreferences());
            }
        } else if (varName.equals(PORTLET_SESSION)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            value = facesContext.getExternalContext().getSession(true);
        } else if (varName.equals(PORTLET_SESSION_SCOPE)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            value = facesContext.getExternalContext().getSessionMap();
        } else if (varName.equals(PORTLET_PREFERENCES)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            PortletRequest portletRequest = getPortletRequest(facesContext);
            if (portletRequest != null) {
                value = portletRequest.getPreferences();
            }
        } else if (varName.equals(PORTLET_PREFERENCES_VALUES)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            PortletRequest portletRequest = getPortletRequest(facesContext);
            if (portletRequest != null) {
                value = portletRequest.getPreferences().getMap();
            }
        } else if (varName.equals(RENDER_REQUEST)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
            if ((portletPhase == Bridge.PortletPhase.HEADER_PHASE) || (portletPhase == Bridge.PortletPhase.RENDER_PHASE)) {
                value = getPortletRequest(facesContext);
            } else {
                throw new ELException("Unable to get renderRequest during " + portletPhase);
            }
        } else if (varName.equals(RENDER_RESPONSE)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
            if ((portletPhase == Bridge.PortletPhase.HEADER_PHASE) || (portletPhase == Bridge.PortletPhase.RENDER_PHASE)) {
                value = getPortletResponse(facesContext);
            } else {
                throw new ELException("Unable to get renderResponse during " + portletPhase);
            }
        } else if (varName.equals(RESOURCE_REQUEST)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
            if (portletPhase == Bridge.PortletPhase.RESOURCE_PHASE) {
                value = getPortletRequest(facesContext);
            } else {
                throw new ELException("Unable to get resourceRequest during " + portletPhase);
            }
        } else if (varName.equals(RESOURCE_RESPONSE)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
            if (portletPhase == Bridge.PortletPhase.RESOURCE_PHASE) {
                value = getPortletResponse(facesContext);
            } else {
                throw new ELException("Unable to get renderResponse during " + portletPhase);
            }
        } else {
            value = super.resolveVariable(elContext, varName);
        }
    }
    return value;
}
Also used : FacesContext(javax.faces.context.FacesContext) LegacyBridgeContext(com.liferay.faces.bridge.context.internal.LegacyBridgeContext) ContextMapFactory(com.liferay.faces.bridge.context.map.internal.ContextMapFactory) MutablePreferenceMap(com.liferay.faces.bridge.preference.internal.MutablePreferenceMap) PortletRequest(javax.portlet.PortletRequest) PortletSession(javax.portlet.PortletSession) ExternalContext(javax.faces.context.ExternalContext) PortletConfig(javax.portlet.PortletConfig) BridgeConfig(javax.portlet.faces.BridgeConfig) PortletContext(javax.portlet.PortletContext) ELException(javax.el.ELException) Bridge(javax.portlet.faces.Bridge)

Example 4 with BridgeConfig

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

the class IPCPhaseListener method processOutgoingPublicRenderParameters.

/**
 * This method processes the "outgoing" Public Render Parameters in accordance with Section 5.3.3 of the Spec.
 */
public void processOutgoingPublicRenderParameters(FacesContext facesContext) {
    try {
        // since this phase listener is being executed within the portlet lifecycle.
        if (facesContext != null) {
            ExternalContext externalContext = facesContext.getExternalContext();
            PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
            StateAwareResponse stateAwareResponse = (StateAwareResponse) externalContext.getResponse();
            // Section 5.3.3 requires the phase listener to re-examine the public render parameters. For each one
            // that has been changed in the model, its new value must be set in the response, so that when the
            // RENDER_PHASE of the Portlet 2.0 lifecycle executes, this phase listener will be able to inject the
            // new value into the model of other portlets that are participating in the IPC.
            BridgeConfig bridgeConfig = RequestMapUtil.getBridgeConfig(portletRequest);
            Map<String, String[]> publicParameterMappings = bridgeConfig.getPublicParameterMappings();
            if (publicParameterMappings != null) {
                PortletConfig portletConfig = RequestMapUtil.getPortletConfig(portletRequest);
                String portletName = portletConfig.getPortletName();
                Map<String, String[]> publicParameterMap = portletRequest.getPublicParameterMap();
                Set<String> publicRenderParameterNames = publicParameterMappings.keySet();
                // For each of the public render parameters found in the WEB-INF/faces-config.xml file:
                for (String prefixedParameterName : publicRenderParameterNames) {
                    String[] modelExpressions = publicParameterMappings.get(prefixedParameterName);
                    if (modelExpressions != null) {
                        String parameterPrefix;
                        String nonPrefixedParameterName;
                        int colonPos = prefixedParameterName.indexOf(":");
                        if (colonPos > 0) {
                            parameterPrefix = prefixedParameterName.substring(0, colonPos);
                            nonPrefixedParameterName = prefixedParameterName.substring(colonPos + 1);
                        } else {
                            parameterPrefix = null;
                            nonPrefixedParameterName = prefixedParameterName;
                        }
                        for (String originalModelEL : modelExpressions) {
                            String[] parameterValues = publicParameterMap.get(nonPrefixedParameterName);
                            String parameterValue = null;
                            if ((parameterValues != null) && (parameterValues.length > 0)) {
                                parameterValue = parameterValues[0];
                            }
                            PublicRenderParameter publicRenderParameter = new PublicRenderParameterImpl(parameterPrefix, parameterValue, originalModelEL, portletName);
                            if (publicRenderParameter.isForThisPortlet()) {
                                String modelValue = publicRenderParameter.getModelValue(facesContext);
                                boolean modelValueHasChanged = publicRenderParameter.isModelValueChanged(facesContext);
                                if (logger.isTraceEnabled()) {
                                    logger.trace("portletName=[{0}] public render parameter=[{1}] parameterValue=[{2}] modelValue=[{3}] modelValueHasChanged=[{4}]", portletName, nonPrefixedParameterName, parameterValue, modelValue, modelValueHasChanged);
                                }
                                if (modelValueHasChanged) {
                                    logger.debug("Setting render parameter=[{0}] in response because modelValue=[{1}] has changed", nonPrefixedParameterName, modelValue);
                                    stateAwareResponse.setRenderParameter(nonPrefixedParameterName, modelValue);
                                } else {
                                    logger.debug("NOT setting render parameter=[{0}] in response because modelValue=[{1}] has NOT changed", nonPrefixedParameterName, modelValue);
                                }
                            } else {
                                logger.debug("NOT setting render parameter=[{0}] in response because it is NOT for this portletName=[{1}]", nonPrefixedParameterName, portletName);
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        // There's no point in throwing a RuntimeException of any kind like FacesException because the Faces
        // runtime will swallow it. So the best we can do is log the exception.
        logger.error(e);
    }
}
Also used : StateAwareResponse(javax.portlet.StateAwareResponse) PortletRequest(javax.portlet.PortletRequest) ExternalContext(javax.faces.context.ExternalContext) PortletConfig(javax.portlet.PortletConfig) BridgeConfig(javax.portlet.faces.BridgeConfig)

Example 5 with BridgeConfig

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

the class BridgeCompatImpl method doFacesRequest.

@Override
public void doFacesRequest(HeaderRequest headerRequest, HeaderResponse headerResponse) throws BridgeDefaultViewNotSpecifiedException, BridgeUninitializedException, BridgeException {
    checkNull(headerRequest, headerResponse);
    if (isInitialized()) {
        PortletConfig wrappedPortletConfig = BridgePortletConfigFactory.getPortletConfigInstance(getPortletConfig());
        BridgeConfig bridgeConfig = BridgeConfigFactory.getBridgeConfigInstance(wrappedPortletConfig);
        BridgePhase bridgePhase = new BridgePhaseHeaderImpl(headerRequest, headerResponse, wrappedPortletConfig, bridgeConfig);
        bridgePhase.execute();
    } else {
        throw new BridgeUninitializedException();
    }
}
Also used : PortletConfig(javax.portlet.PortletConfig) BridgeConfig(javax.portlet.faces.BridgeConfig) BridgeUninitializedException(javax.portlet.faces.BridgeUninitializedException)

Aggregations

BridgeConfig (javax.portlet.faces.BridgeConfig)14 PortletConfig (javax.portlet.PortletConfig)9 FacesContext (javax.faces.context.FacesContext)5 BridgeUninitializedException (javax.portlet.faces.BridgeUninitializedException)5 ExternalContext (javax.faces.context.ExternalContext)4 PortletRequest (javax.portlet.PortletRequest)3 BridgeNotAFacesRequestException (javax.portlet.faces.BridgeNotAFacesRequestException)3 List (java.util.List)2 PortletContext (javax.portlet.PortletContext)2 PortletSession (javax.portlet.PortletSession)2 UIViewRootBridgeImpl (com.liferay.faces.bridge.component.internal.UIViewRootBridgeImpl)1 IncongruityContext (com.liferay.faces.bridge.context.internal.IncongruityContext)1 LegacyBridgeContext (com.liferay.faces.bridge.context.internal.LegacyBridgeContext)1 ContextMapFactory (com.liferay.faces.bridge.context.map.internal.ContextMapFactory)1 MutablePreferenceMap (com.liferay.faces.bridge.preference.internal.MutablePreferenceMap)1 BridgeRequestScope (com.liferay.faces.bridge.scope.internal.BridgeRequestScope)1 ConfiguredServletMapping (com.liferay.faces.util.config.ConfiguredServletMapping)1 ConfiguredSystemEventListener (com.liferay.faces.util.config.ConfiguredSystemEventListener)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1