You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by so...@apache.org on 2008/02/19 22:11:12 UTC

svn commit: r629232 - in /myfaces/trinidad/branches/1.2.6.1-branch: pom.xml trinidad-impl/pom.xml trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java

Author: sobryan
Date: Tue Feb 19 13:11:10 2008
New Revision: 629232

URL: http://svn.apache.org/viewvc?rev=629232&view=rev
Log:
TRINIDAD-134 - StateManagerImpl is not fully compatible with JSR-301

* I added some logic to construct a PortletNamingContainerUIViewRoot
  if we have a PortletRequest AND the current UIViewRoot is provided
  by the R.I.  This is the same logic used in the bridge.

Modified:
    myfaces/trinidad/branches/1.2.6.1-branch/pom.xml
    myfaces/trinidad/branches/1.2.6.1-branch/trinidad-impl/pom.xml
    myfaces/trinidad/branches/1.2.6.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java

Modified: myfaces/trinidad/branches/1.2.6.1-branch/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.6.1-branch/pom.xml?rev=629232&r1=629231&r2=629232&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.6.1-branch/pom.xml (original)
+++ myfaces/trinidad/branches/1.2.6.1-branch/pom.xml Tue Feb 19 13:11:10 2008
@@ -367,6 +367,13 @@
       </dependency>
 
       <dependency>
+        <groupId>org.apache.myfaces.portlet-bridge</groupId>
+        <artifactId>portlet-bridge-api</artifactId>
+        <version>1.0.0-alpha</version>
+        <scope>provided</scope>
+      </dependency>
+
+      <dependency>
         <groupId>org.apache.myfaces.core</groupId>
         <artifactId>myfaces-api</artifactId>
         <version>${myfaces.version}</version>

Modified: myfaces/trinidad/branches/1.2.6.1-branch/trinidad-impl/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.6.1-branch/trinidad-impl/pom.xml?rev=629232&r1=629231&r2=629232&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.6.1-branch/trinidad-impl/pom.xml (original)
+++ myfaces/trinidad/branches/1.2.6.1-branch/trinidad-impl/pom.xml Tue Feb 19 13:11:10 2008
@@ -208,6 +208,11 @@
     </dependency>
 
     <dependency>
+      <groupId>org.apache.myfaces.portlet-bridge</groupId>
+      <artifactId>portlet-bridge-api</artifactId>
+    </dependency>
+
+    <dependency>
       <groupId>jstl</groupId>
       <artifactId>jstl</artifactId>
     </dependency>

Modified: myfaces/trinidad/branches/1.2.6.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.6.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java?rev=629232&r1=629231&r2=629232&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.6.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java (original)
+++ myfaces/trinidad/branches/1.2.6.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java Tue Feb 19 13:11:10 2008
@@ -52,6 +52,11 @@
 
 import java.io.IOException;
 
+import javax.portlet.faces.annotation.PortletNamingContainer;
+import javax.portlet.faces.component.PortletNamingContainerUIViewRoot;
+
+import org.apache.myfaces.trinidad.util.ExternalContextUtils;
+
 /**
  * StateManager that handles a hybrid client/server strategy:  a
  * SerializedView is stored on the server, and only a small token
@@ -984,6 +989,17 @@
         UIViewRoot newRoot = (UIViewRoot) 
           fc.getApplication().createComponent(UIViewRoot.COMPONENT_TYPE);
         
+        //This code handles automatic namespacing in a JSR-301 environment
+        if(ExternalContextUtils.isPortlet(fc.getExternalContext())) 
+        {
+          //To avoid introducing a runtime dependency on the bridge,
+          //this method should only be executed when we have a portlet
+          //request.  If we do have a portlet request then the bridge
+          //should be available anyway.
+          newRoot = _getPortletRoot(newRoot);
+        }
+
+        
         // must call restoreState so that we setup attributes, listeners,
         // uniqueIds, etc ...
         newRoot.restoreState(fc, viewRootState);
@@ -1002,6 +1018,37 @@
       
       return null;
     }
+    
+    /**
+     * This should only be executed if we are currently in a Portlet Request.
+     * If executed, this method introduces a dependency on the JSR-301 bridge
+     * which is required for Trinidad to run in a portal environment.  If this
+     * method is not run, then the bridge api's remain optional at runtime.
+     * 
+     * This method checks the current UIViewRoot to see if it is a 
+     * PortletNamingContainer.  If it is, then this class simply returns the
+     * UIViewRoot.  If it does not then the current UIViewRoot is used to create
+     * a new PortletNamingContainerUIViewRoot.
+     */
+    private UIViewRoot _getPortletRoot(UIViewRoot root) 
+    {
+      Class<? extends UIViewRoot> rootClass = root.getClass();
+      //If the current root is not the real UIViewRoot object in faces then
+      //is no need to escape it.  It is assumed it handles namespacing on its
+      //own.  This is the same as the logic in the JSR-301 Bridge spec.
+      if(rootClass == UIViewRoot.class) 
+      {
+        _LOG.fine("Creating PortletUIViewRoot for use with the portal.");
+        root = new PortletNamingContainerUIViewRoot(root);
+      }
+      
+      //TODO: Do we need a warning here if the view root is not annotated 
+      //properly?  This could happen if another renderkit is involved and does
+      //not correctly implement JSR-301.  This will NOT be an issue in Trin only
+      //environments.
+      return root;
+    }
+
   }