Search in sources :

Example 11 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(ActionRequest actionRequest, ActionResponse actionResponse) throws BridgeDefaultViewNotSpecifiedException, BridgeUninitializedException, BridgeException {
    checkNull(actionRequest, actionResponse);
    if (initialized) {
        String nonFacesTargetPath = actionRequest.getParameter(Bridge.NONFACES_TARGET_PATH_PARAMETER);
        if (nonFacesTargetPath != null) {
            throw new BridgeNotAFacesRequestException(nonFacesTargetPath);
        }
        PortletConfig wrappedPortletConfig = BridgePortletConfigFactory.getPortletConfigInstance(portletConfig);
        BridgeConfig bridgeConfig = BridgeConfigFactory.getBridgeConfigInstance(wrappedPortletConfig);
        BridgePhase bridgePhase = new BridgePhaseActionImpl(actionRequest, actionResponse, wrappedPortletConfig, bridgeConfig);
        bridgePhase.execute();
    } else {
        throw new BridgeUninitializedException();
    }
}
Also used : PortletConfig(javax.portlet.PortletConfig) BridgeNotAFacesRequestException(javax.portlet.faces.BridgeNotAFacesRequestException) BridgeConfig(javax.portlet.faces.BridgeConfig) BridgeUninitializedException(javax.portlet.faces.BridgeUninitializedException)

Example 12 with BridgeConfig

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

the class IPCPhaseListener method processIncomingPublicRenderParameters.

/**
 * This method processes the "incoming" Public Render Parameters in accordance with Section 5.3.2 of the Spec.
 */
public void processIncomingPublicRenderParameters(FacesContext facesContext) {
    try {
        // since this phase listener is being executed within the portlet lifecycle.
        if (facesContext != null) {
            // Section 5.3.2 requires the phase listener to inject the public render parameters into the
            // Model concern of the MVC design pattern (as in JSF model managed-beans) after RESTORE_VIEW
            // phase completes. This is accomplished below by evaluating the EL expressions found in the
            // <model-el>...</model-el> section of the WEB-INF/faces-config.xml file.
            ExternalContext externalContext = facesContext.getExternalContext();
            PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
            BridgeConfig bridgeConfig = RequestMapUtil.getBridgeConfig(portletRequest);
            Map<String, String[]> publicParameterMappings = bridgeConfig.getPublicParameterMappings();
            if (publicParameterMappings != null) {
                boolean invokeHandler = false;
                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;
                        }
                        if (publicParameterMap.containsKey(nonPrefixedParameterName)) {
                            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 (logger.isTraceEnabled()) {
                                    logger.trace("portletName=[{0}] public render parameter=[{1}] originalModelEL=[{2}] modifiedModelEL=[{3}] isForThisPortlet=[{4}]", portletName, nonPrefixedParameterName, originalModelEL, publicRenderParameter.getModifiedModelEL(), publicRenderParameter.isForThisPortlet());
                                }
                                if (publicRenderParameter.isForThisPortlet()) {
                                    logger.debug("Injecting render parameter=[{0}] value=[{1}] into expression=[{2}]", nonPrefixedParameterName, parameterValue, publicRenderParameter.getModifiedModelEL());
                                    invokeHandler = publicRenderParameter.injectIntoModel(facesContext);
                                } else {
                                    logger.debug("NOT injecting render parameter=[{0}] value=[{1}] into expression=[{2}] because it is NOT for this portletName=[{3}]", nonPrefixedParameterName, parameterValue, publicRenderParameter.getModifiedModelEL(), portletName);
                                }
                            }
                        } else {
                            logger.debug("NOT injecting render parameter=[{0}] because it is not found in the public parameter map", nonPrefixedParameterName);
                        }
                    }
                }
                // processing that might be necessary.
                if (invokeHandler) {
                    String bridgePublicRenderParameterHandlerAttributeName = Bridge.BRIDGE_PACKAGE_PREFIX + portletName + "." + Bridge.BRIDGE_PUBLIC_RENDER_PARAMETER_HANDLER;
                    logger.trace("bridgePublicRenderParameterHandlerAttributeName=[{0}]", bridgePublicRenderParameterHandlerAttributeName);
                    BridgePublicRenderParameterHandler bridgePublicRenderParameterHandler = (BridgePublicRenderParameterHandler) externalContext.getApplicationMap().get(bridgePublicRenderParameterHandlerAttributeName);
                    if (bridgePublicRenderParameterHandler == null) {
                        bridgePublicRenderParameterHandler = BridgePublicRenderParameterHandlerFactory.getBridgePublicRenderParameterHandlerInstance(portletConfig);
                    }
                    if (bridgePublicRenderParameterHandler != null) {
                        logger.debug("Invoking {0} for class=[{1}]", bridgePublicRenderParameterHandler, bridgePublicRenderParameterHandler.getClass());
                        bridgePublicRenderParameterHandler.processUpdates(facesContext);
                    }
                }
            }
        }
    } 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 : BridgePublicRenderParameterHandler(javax.portlet.faces.BridgePublicRenderParameterHandler) PortletRequest(javax.portlet.PortletRequest) ExternalContext(javax.faces.context.ExternalContext) PortletConfig(javax.portlet.PortletConfig) BridgeConfig(javax.portlet.faces.BridgeConfig)

Example 13 with BridgeConfig

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

the class BridgeConfigFactoryImpl method getBridgeConfig.

@Override
public BridgeConfig getBridgeConfig(PortletConfig portletConfig) {
    PortletContext portletContext = portletConfig.getPortletContext();
    BridgeConfig bridgeConfig = (BridgeConfig) portletContext.getAttribute(BridgeConfigFactoryImpl.class.getName());
    if (bridgeConfig == null) {
        bridgeConfig = new BridgeConfigImpl(portletConfig);
        portletContext.setAttribute(BridgeConfigFactoryImpl.class.getName(), bridgeConfig);
    }
    return bridgeConfig;
}
Also used : PortletContext(javax.portlet.PortletContext) BridgeConfig(javax.portlet.faces.BridgeConfig)

Example 14 with BridgeConfig

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

the class BridgeRedirectURLLiferayImpl method toString.

@Override
public String toString() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
        ExternalContext externalContext = facesContext.getExternalContext();
        Map<String, Object> requestMap = externalContext.getRequestMap();
        BridgeConfig bridgeConfig = (BridgeConfig) requestMap.get(BridgeConfig.class.getName());
        PortletResponse portletResponse = (PortletResponse) externalContext.getResponse();
        LiferayPortletResponse liferayPortletResponse = new LiferayPortletResponse(portletResponse);
        PortletURL renderURL = liferayPortletResponse.createRenderURL();
        renderURL.setParameter(bridgeConfig.getViewIdRenderParameterName(), wrappedBridgeRedirectURL.getViewId());
        Map<String, String[]> parameterMap = getParameterMap();
        Set<Map.Entry<String, String[]>> entrySet = parameterMap.entrySet();
        for (Map.Entry<String, String[]> mapEntry : entrySet) {
            String parameterName = mapEntry.getKey();
            String[] parameterValues = mapEntry.getValue();
            renderURL.setParameter(parameterName, parameterValues);
        }
        return renderURL.toString();
    } else {
        return wrappedBridgeRedirectURL.toString();
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) PortletResponse(javax.portlet.PortletResponse) ExternalContext(javax.faces.context.ExternalContext) BridgeConfig(javax.portlet.faces.BridgeConfig) PortletURL(javax.portlet.PortletURL) Map(java.util.Map)

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