You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mf...@apache.org on 2010/08/27 00:52:23 UTC

svn commit: r989964 - in /myfaces/portlet-bridge/core/trunk_2.0.x: api/src/main/java/javax/portlet/faces/ impl/src/main/java/org/apache/myfaces/portlet/faces/context/

Author: mfreedman
Date: Thu Aug 26 22:52:23 2010
New Revision: 989964

URL: http://svn.apache.org/viewvc?rev=989964&view=rev
Log:
PORTLETBRIDGE-167: P2.0Bridge: Update impl to support spec change for config of defaultRenderKitId

Modified:
    myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/Bridge.java
    myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/GenericFacesPortlet.java
    myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java

Modified: myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/Bridge.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/Bridge.java?rev=989964&r1=989963&r2=989964&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/Bridge.java (original)
+++ myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/Bridge.java Thu Aug 26 22:52:23 2010
@@ -104,7 +104,18 @@ Bridge
    */
   public static final String PRESERVE_ACTION_PARAMS = "preserveActionParams";
 
-
+  /** A PortletContext attribute that a portlet can set prior
+   * to calling the bridge's init() method to configure the bridge to default
+   * the renderKitId used for rendering this portlet to the named Id.  In Faces, the 
+   * default renderKitId is set in the faces-config.xml and is application wide.  In 1.2
+   * this can be overidden by a specially named request parameter. To allow differing portlets
+   * in the same app to use different default render kits, without having to add this 
+   * parameter, the portlet can set this attribute prior to the bridge init().  The bridge 
+   * will recognize this configuration value and on each request add the special faces
+   * request parameter to the request (if its not already present).
+   */
+  public static final String DEFAULT_RENDERKIT_ID = "defaultRenderKitId";
+  
   /** A PortletContext attribute that a portlet can set prior
    * to calling the bridge's init() method to configure the bridge to exclude
    * specific attributes from its bridge request scope. Value is a comma delimited

Modified: myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/GenericFacesPortlet.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/GenericFacesPortlet.java?rev=989964&r1=989963&r2=989964&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/GenericFacesPortlet.java (original)
+++ myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/GenericFacesPortlet.java Thu Aug 26 22:52:23 2010
@@ -174,6 +174,13 @@ public class GenericFacesPortlet extends
     Boolean preserveActionParams = new Boolean(isPreserveActionParameters());
     getPortletContext().setAttribute(Bridge.BRIDGE_PACKAGE_PREFIX + getPortletName() + "." + 
                                      Bridge.PRESERVE_ACTION_PARAMS, preserveActionParams);
+    
+    String defaultRenderKitId = getDefaultRenderKitId();
+    if (defaultRenderKitId != null)
+    {
+      getPortletContext().setAttribute(Bridge.BRIDGE_PACKAGE_PREFIX + getPortletName() + "." + 
+                                     Bridge.DEFAULT_RENDERKIT_ID, defaultRenderKitId);
+    }
 
     Map defaultViewIdMap = getDefaultViewIdMap();
     getPortletContext().setAttribute(Bridge.BRIDGE_PACKAGE_PREFIX + getPortletName() + "." + 
@@ -403,6 +410,23 @@ public class GenericFacesPortlet extends
       return Boolean.parseBoolean(preserveActionParams);
     }
   }
+  
+  /**
+   * Returns a String defining the default render kit id the bridge should ensure for this portlet.
+   * If non-null, this value is used to override any default render kit id set on an app wide basis 
+   * in the faces-config.xml. This
+   * default implementation reads the values from the portlet init_param
+   * javax.portlet.faces.defaultRenderKitId.  If not present, null is returned.
+   * 
+   * @return a boolean indicating whether or not the bridge should preserve all the
+   * action parameters in the subsequent renders that occur in the same scope.
+   */
+  public String getDefaultRenderKitId()
+  {
+    return 
+      getPortletConfig().getInitParameter(Bridge.BRIDGE_PACKAGE_PREFIX + 
+                                          Bridge.DEFAULT_RENDERKIT_ID);
+  }   
 
   /**
    * Returns the className of the bridge implementation this portlet uses. Subclasses override to

Modified: myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java?rev=989964&r1=989963&r2=989964&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java (original)
+++ myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java Thu Aug 26 22:52:23 2010
@@ -120,6 +120,7 @@ public class PortletExternalContextImpl
   private Object mTempNonPortletResponse;
   
   private String mPortletName;
+  private String mDefaultRenderKitId;
 
   // External context maps
   private Map<String, Object> mApplicationMap = null;
@@ -133,8 +134,8 @@ public class PortletExternalContextImpl
 
   // maps for internal parameters (eg, those specified in query string of
   // any defaultViewId) -- 
-  private Map<String, String> mTempExtraRequestParameterMap = Collections.emptyMap();
-  private Map<String, String[]> mTempExtraRequestParameterValuesMap = Collections.emptyMap();
+  private Map<String, String> mTempExtraRequestParameterMap = null;
+  private Map<String, String[]> mTempExtraRequestParameterValuesMap = null;
 
   private PortletRequestHeaders mPortletRequestHeaders = null;
 
@@ -160,6 +161,8 @@ public class PortletExternalContextImpl
     mPortletResponse = portletResponse;
     
     mPortletName = (String) mPortletRequest.getAttribute(BridgeImpl.PORTLET_NAME_ATTRIBUTE);
+    mDefaultRenderKitId = (String) mPortletContext.getAttribute(Bridge.BRIDGE_PACKAGE_PREFIX + mPortletName + 
+                                              "." + Bridge.DEFAULT_RENDERKIT_ID);
 
     mFacesMappings = (List<String>) mPortletRequest.getAttribute(FACES_MAPPING_ATTRIBUTE);
     
@@ -1038,6 +1041,11 @@ public class PortletExternalContextImpl
   {
     if (mRequestParameterMap == null)
     {
+      //  Faces 1.2 allows a request to override the default renderkit id through use
+      // of a 'known' request parameter.  We use this to allow each portlet in a app
+      // to configure their own default. 
+     addDefaultRenderKitIdToRequest();  
+      
       // In cases where the viewId is derived from either an attribute set by the portlet 
       // or from the defaultView Map, the viewId can contain additional querystring parameters.
       // These are held by the ExternalContext in an internal temp Map until this method
@@ -1055,6 +1063,11 @@ public class PortletExternalContextImpl
   {
     if (mRequestParameterValuesMap == null)
     {
+      //  Faces 1.2 allows a request to override the default renderkit id through use
+      // of a 'known' request parameter.  We use this to allow each portlet in a app
+      // to configure their own default. 
+      addDefaultRenderKitIdToRequest();
+      
       // In cases where the viewId is derived from either an attribute set by the portlet 
       // or from the defaultView Map, the viewId can contain additional querystring parameters.
       // These are held by the ExternalContext in an internal temp Map until this method
@@ -1542,6 +1555,36 @@ public class PortletExternalContextImpl
   }
 
   // End of JSF 1.2 API
+  
+  private void addDefaultRenderKitIdToRequest()
+  {
+    if (mDefaultRenderKitId == null) return;
+    
+    if (mPortletRequest.getParameter(ResponseStateManager.RENDER_KIT_ID_PARAM) != null)
+    {
+      // request already has one
+      return;
+    }
+    
+    if (mTempExtraRequestParameterMap == null)
+    {
+      mTempExtraRequestParameterMap = (Map<String, String>) new HashMap(1);
+    }
+    if (mTempExtraRequestParameterMap.get(ResponseStateManager.RENDER_KIT_ID_PARAM) == null)
+    {
+      mTempExtraRequestParameterMap.put(ResponseStateManager.RENDER_KIT_ID_PARAM, mDefaultRenderKitId);
+    }
+    
+    if (mTempExtraRequestParameterValuesMap == null)
+    {
+      mTempExtraRequestParameterValuesMap = (Map<String, String[]>) new HashMap(1);
+    }
+    if (mTempExtraRequestParameterValuesMap.get(ResponseStateManager.RENDER_KIT_ID_PARAM) == null)
+    {
+      mTempExtraRequestParameterValuesMap.put(ResponseStateManager.RENDER_KIT_ID_PARAM, new String[] {mDefaultRenderKitId});
+    }
+
+  }
 
   private Bridge.PortletPhase getPortletPhase()
   {