/** * Indicates whether the current request is executing in the portlet container. * * @return <code>true</code> if the request is a portlet request, otherwise <code>false</code>. */ public static boolean isPortletRequest() { FacesContext facesContext = FacesContext.getCurrentInstance(); return isPortletRequest(facesContext); }
/** * Indicates the portlet lifecycle phase currently being executed within the execution of the Faces lifecycle. * * @return The portlet lifecycle phase if the current request is executing within a portlet environment. Otherwise * <code>null</code>. */ public static Bridge.PortletPhase getPortletRequestPhase() { FacesContext facesContext = FacesContext.getCurrentInstance(); return getPortletRequestPhase(facesContext); }
@Override public String getContainerClientId(FacesContext facesContext) { if (BridgeUtil.isPortletRequest(facesContext)) { if (namespace == null) { ExternalContext externalContext = facesContext.getExternalContext(); namespace = externalContext.encodeNamespace(""); } return namespace; } else { return null; } }
/** * Indicates whether the current request is executing in the portlet container. If it returns <code>true</code> the * request is a portlet request, otherwise it is not. */ public static boolean isPortletRequest() { FacesContext ctx = FacesContext.getCurrentInstance(); // This method might be called during App startup (via a context listener) and hence no FacesContext // For example a renderkit might createComponents during such time -- as the bridge overrides faces Application // which implements createComponent and calls this method (to see if we need to wrap/replace with the // NamingContainer if (ctx == null) { return false; } return null != getPortletRequestPhase(); }
@Override public String getContainerClientId(FacesContext facesContext) { if (BridgeUtil.isPortletRequest()) { if (namespace == null) { ExternalContext externalContext = facesContext.getExternalContext(); namespace = externalContext.encodeNamespace(""); } return namespace; } else { return null; } }
if ((BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.ACTION_PHASE || BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.RESOURCE_PHASE))
/** * Implements NamingContainer semantics. Ensures that the returned identifier contains the consumer (portal) provided unique * portlet id. This ensures that those components in this NamingContainer generate ids which will not collide in the * consumer page. */ @Override public String getContainerClientId(FacesContext context) { if (BridgeUtil.isPortletRequest()) { if (namespace == null) { ExternalContext externalContext = context.getExternalContext(); namespace = externalContext.encodeNamespace(""); } return namespace; } else { return null; } } }
if ((BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.ACTION_PHASE || BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.RESOURCE_PHASE))
@Override public void setId(String id) { if (BridgeUtil.isPortletRequest()) { if (namespace == null) { getContainerClientId(FacesContext.getCurrentInstance()); } id = namespace; } super.setId(id); }
@Override public String getRedirectURL(FacesContext facesContext, String viewId, Map<String, List<String>> parameters, boolean includeViewParams) { BridgeContext bridgeContext = BridgeContext.getCurrentInstance(); PortletPhase portletRequestPhase = BridgeUtil.getPortletRequestPhase(); // Determine whether or not it is necessary to work-around the patch applied to Mojarra in JAVASERVERFACES-3023 boolean workaroundMojarra = (MOJARRA_DETECTED) && ((portletRequestPhase == Bridge.PortletPhase.ACTION_PHASE) || (portletRequestPhase == Bridge.PortletPhase.EVENT_PHASE)); if (workaroundMojarra) { bridgeContext.getAttributes().put(RESPONSE_CHARACTER_ENCODING, "UTF-8"); } String redirectURL = super.getRedirectURL(facesContext, viewId, parameters, includeViewParams); if (workaroundMojarra) { bridgeContext.getAttributes().remove(RESPONSE_CHARACTER_ENCODING); } return redirectURL; } }
/** * <p>This method fixes a problem with {@link UIComponent#findComponent(String)} where sometimes it is unable to * find components due to incorrect clientId values. For more info, see the following issues: * * <ul> * <li>http://issues.liferay.com/browse/FACES-198</li> * <li>http://jira.icesoft.org/browse/ICE-6659</li> * <li>http://jira.icesoft.org/browse/ICE-6667</li> * </ul> * </p> */ @Override public void setId(String id) { if (BridgeUtil.isPortletRequest()) { super.setId(getContainerClientId(FacesContext.getCurrentInstance())); } }
@Override public String getRedirectURL(FacesContext facesContext, String viewId, Map<String, List<String>> parameters, boolean includeViewParams) { BridgeContext bridgeContext = BridgeContext.getCurrentInstance(); PortletPhase portletRequestPhase = BridgeUtil.getPortletRequestPhase(); // Determine whether or not it is necessary to work-around the patch applied to Mojarra in JAVASERVERFACES-3023 boolean workaroundMojarra = (MOJARRA_DETECTED) && ((portletRequestPhase == Bridge.PortletPhase.ACTION_PHASE) || (portletRequestPhase == Bridge.PortletPhase.EVENT_PHASE)); if (workaroundMojarra) { bridgeContext.getAttributes().put(RESPONSE_CHARACTER_ENCODING, "UTF-8"); } String redirectURL = super.getRedirectURL(facesContext, viewId, parameters, includeViewParams); if (workaroundMojarra) { bridgeContext.getAttributes().remove(RESPONSE_CHARACTER_ENCODING); } return redirectURL; } }
if (!BridgeUtil.isPortletRequest() || base != null)
@Override protected BaseURL toBaseURL() throws MalformedURLException { BaseURL baseURL; if (BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.ACTION_PHASE) { baseURL = createRenderURL(uri); baseURL.setParameter(viewIdRenderParameterName, viewId); 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(); baseURL.setParameter(parameterName, parameterValues); } } else { baseURL = super.toBaseURL(); } return baseURL; } }
if (!BridgeUtil.isPortletRequest() || base != null)
@Override protected BaseURL toBaseURL() throws MalformedURLException { BaseURL baseURL; if (BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.ACTION_PHASE) { baseURL = createRenderURL(uri); baseURL.setParameter(viewIdRenderParameterName, viewId); 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(); baseURL.setParameter(parameterName, parameterValues); } } else { baseURL = super.toBaseURL(); } return baseURL; } }
/** * <p>This method fixes a problem with {@link UIComponent#findComponent(String)} where sometimes it is unable to * find components due to incorrect clientId values. For more info, see the following issues: * * <ul> * <li>http://issues.liferay.com/browse/FACES-198</li> * <li>http://jira.icesoft.org/browse/ICE-6659</li> * <li>http://jira.icesoft.org/browse/ICE-6667</li> * </ul> * </p> */ @Override public void setId(String id) { if (BridgeUtil.isPortletRequest()) { super.setId(getContainerClientId(FacesContext.getCurrentInstance())); } }
@Override protected BaseURL toBaseURL() throws MalformedURLException { BaseURL baseURL; // If this is executing during the ACTION_PHASE of the portlet lifecycle, then if (BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.ACTION_PHASE) { // TCK NOTE: The only use-case in which the TCK will invoke this method is // TestPage039-requestNoScopeOnRedirectTest. During the test, this method will be called when a <redirect/> // is encountered in a navigation-rule during the ACTION_PHASE of the portlet lifecycle. When this happens, // the navigation-handler will attempt to call ViewHandler#getResourceURL(String). The Mojarra // MultiViewHandler.getResourceURL(String) method is implemented in such a way that it calls // ExternalContext.encodeActionURL(ExternalContext.encodeResourceURL(url)). The return value of those calls // will ultimately be passed to the ExternalContext.redirect(String) method. For this reason, need to return // a simple string-based representation of the URL. baseURL = new BaseURLNonEncodedStringImpl(bridgeURI.toString(), getParameterMap()); } // Otherwise, else { // So far, under all circumstances it seems appropriate to return a simple string-based representation of // the URL. This is the same code as above but keep it this way for now for TCK documentation purposes. baseURL = new BaseURLNonEncodedStringImpl(bridgeURI.toString(), getParameterMap()); } return baseURL; }
/** * Create a new UIComponent subclass, using the mappings defined by previous * calls to the addComponent method of this class. * <p> * @throws FacesException if there is no mapping defined for the specified * componentType, or if an instance of the specified type could not be * created for any reason. */ public javax.faces.component.UIComponent createComponent(String componentType) throws FacesException { UIComponent component = mWrapped.createComponent(componentType); if (BridgeUtil.isPortletRequest() && component.getClass() == UIViewRoot.class && UIViewRoot.class.getAnnotation(PortletNamingContainer.class) == null ) { // replace with our own UIViewRoot component = new PortletNamingContainerUIViewRoot(); } return component; }
if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {