You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bs...@apache.org on 2010/03/07 08:35:56 UTC

svn commit: r919945 - in /myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main: java-templates/org/apache/myfaces/trinidad/component/ java/org/apache/myfaces/trinidad/component/

Author: bsullivan
Date: Sun Mar  7 07:35:56 2010
New Revision: 919945

URL: http://svn.apache.org/viewvc?rev=919945&view=rev
Log:
In order for #{component} to resolve correctly, pushComponentToEL/popComponentFromEL must be called before retrieving attributes or invoking callbacks when performing any kind of traversal. While TRINIDAD-1612 Add support for the new Lifecycle Management Methods (see spec section 3.1.14) covers this for the normal component processXXX methods, this JIRA addresses the other forms of component traversal for both the Trinidad framework itself and its component implementations. In particular, visitTree, invokeOnComponent and FlattenedComponent, processComponent are addressed.

Modified:
    myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXIteratorTemplate.java
    myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/ComponentProcessor.java
    myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java
    myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java
    myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java

Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXIteratorTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXIteratorTemplate.java?rev=919945&r1=919944&r2=919945&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXIteratorTemplate.java (original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXIteratorTemplate.java Sun Mar  7 07:35:56 2010
@@ -86,7 +86,16 @@
       @Override
       protected void process(UIComponent kid, ComponentProcessingContext cpContext) throws IOException
       {
-        childProcessor.processComponent(context, cpContext, kid, callbackContext);
+        kid.pushComponentToEL(context, null);
+
+        try
+        {
+          childProcessor.processComponent(context, cpContext, kid, callbackContext);
+        }
+        finally
+        {
+          kid.popComponentFromEL(context);         
+        }
       }
     };
     boolean processedChildren = runner.run();

Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/ComponentProcessor.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/ComponentProcessor.java?rev=919945&r1=919944&r2=919945&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/ComponentProcessor.java (original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/ComponentProcessor.java Sun Mar  7 07:35:56 2010
@@ -31,7 +31,7 @@
  * Instances of this interface are parameterized by the type of the callbackContext the implementor
  * expects.  The typical usage is that the implementor creates and instance of the desired context
  * and calls a helper method on a different object (for example
- * <code>UIXComponet.processComponent</code> with the desired ComponentProcessor and context
+ * <code>UIXComponent.processComponent</code> with the desired ComponentProcessor and context
  * instances to actually perform the iteration.
  * <p>
  * Because the ComponentProcessor can't look ahead, more complex iteration tasks, such as

Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java?rev=919945&r1=919944&r2=919945&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java (original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java Sun Mar  7 07:35:56 2010
@@ -1095,7 +1095,17 @@
         _flushCachedModel();
       }
 
-      callback.invokeContextCallback(context, this);
+      pushComponentToEL(context, null);
+      
+      try
+      {
+        callback.invokeContextCallback(context, this);
+      }
+      finally
+      {
+        popComponentFromEL(context);
+      }
+      
       return true;
     }
     // If we're on a row, set the currency, and invoke

Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java?rev=919945&r1=919944&r2=919945&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java (original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java Sun Mar  7 07:35:56 2010
@@ -165,6 +165,8 @@
       else
       {
         // not a FlattenedComponent, pass the component directly to the ComponentProcessor
+        child.pushComponentToEL(context, null);
+        
         try
         {
           childProcessor.processComponent(context, cpContext, child, callbackContext);
@@ -173,6 +175,7 @@
         {
           // if startDepth is > 0, only the first visible child will be marked as starting a group
           cpContext.resetStartDepth();
+          child.popComponentFromEL(context);
         }
 
         return true;
@@ -433,104 +436,118 @@
       if (!uixComponent.isVisitable(visitContext))
         return false;
   
-      RenderingContext rc = (_isEncodingVisit(visitContext))
-                              ? RenderingContext.getCurrentInstance()
-                              : null;
-  
-  
-      // UIXComponents are allowed to set up their context differently for encoding
-      // than normal processing, so behave differently if this is the RenderResponse
-      // phase
-      if (rc != null)
-      {
-        uixComponent.setupEncodingContext(context, rc);
-      }
-      else
-      {
-        uixComponent.setupVisitingContext(context);
-      }
-  
-      VisitResult visitResult = VisitResult.REJECT;
+      // set up the EL Context with the component.  Note that since we do this after call
+      // isVisitable, any attributes retrieved (liek rendered) that are bound with EL referring
+      // to the current component will be evaluated correctly, however, in the specific case
+      // of rendered, rendered already has this problem in normal JSF traversal since it 
+      // is evaluated by the parent component
+      component.pushComponentToEL(context, null);
+
       boolean doneVisiting = false;
       
       try
       {
-        // invoke the callback for this component
-        visitResult = visitContext.invokeVisitCallback(component, callback);
-  
-        if (visitResult == VisitResult.COMPLETE)
-          doneVisiting = true;
-        else if (visitResult == VisitResult.ACCEPT)
+        RenderingContext rc = (_isEncodingVisit(visitContext))
+                                ? RenderingContext.getCurrentInstance()
+                                : null;
+    
+        // UIXComponents are allowed to set up their context differently for encoding
+        // than normal processing, so behave differently if this is the RenderResponse
+        // phase
+        if (rc != null)
         {
-          // now determine whether we need to visit the children      
-
-          // assume that all UIXComponent NamingContainers always act as NamingContainers,
-          // (unlike <h:form>) and this it is OK to put the optimization where we
-          // don't visit the children if we know that we don't have any ids in this
-          // subtree to visit
-          boolean skipChildren = (uixComponent instanceof NamingContainer) &&
-                                 visitContext.getSubtreeIdsToVisit(uixComponent).isEmpty();
-              
-          // visit the children of the component if we aren't supposed to skip them
-          if (!skipChildren)
+          uixComponent.setupEncodingContext(context, rc);
+        }
+        else
+        {
+          uixComponent.setupVisitingContext(context);
+        }
+    
+        VisitResult visitResult = VisitResult.REJECT;
+        
+        try
+        {
+          // invoke the callback for this component
+          visitResult = visitContext.invokeVisitCallback(component, callback);
+    
+          if (visitResult == VisitResult.COMPLETE)
+            doneVisiting = true;
+          else if (visitResult == VisitResult.ACCEPT)
           {
-            // setup any context needed for visiting the children of the component as opposed
-            // to the component itself
-            if (rc != null)
-            {
-              uixComponent._setupChildrenEncodingContext(context, rc);
-            }
-            else
-            {
-              uixComponent.setupChildrenVisitingContext(context);
-            }
-            
-            
-            try
-            {
-              // determine whether this visit should be iterating.  If it shouldn't, don't
-              // even call the protected hook.  We currently don't iterate during the
-              // restore view phase when we are visiting all of the components.
-              boolean noIterate = (visitContext.getIdsToVisit() == VisitContext.ALL_IDS) &&
-                                  (context.getCurrentPhaseId() == PhaseId.RESTORE_VIEW);
+            // now determine whether we need to visit the children      
+  
+            // assume that all UIXComponent NamingContainers always act as NamingContainers,
+            // (unlike <h:form>) and this it is OK to put the optimization where we
+            // don't visit the children if we know that we don't have any ids in this
+            // subtree to visit
+            boolean skipChildren = (uixComponent instanceof NamingContainer) &&
+                                   visitContext.getSubtreeIdsToVisit(uixComponent).isEmpty();
                 
-              doneVisiting =  (noIterate)
-                                ? uixComponent._visitAllChildren(visitContext, callback)
-                                : uixComponent.visitChildren(visitContext, callback);
-            }
-            finally
+            // visit the children of the component if we aren't supposed to skip them
+            if (!skipChildren)
             {
-              // teardown any context initialized above
+              // setup any context needed for visiting the children of the component as opposed
+              // to the component itself
               if (rc != null)
               {
-                uixComponent._tearDownChildrenEncodingContext(context, rc);
+                uixComponent._setupChildrenEncodingContext(context, rc);
               }
               else
               {
-                uixComponent.tearDownChildrenVisitingContext(context);
+                uixComponent.setupChildrenVisitingContext(context);
+              }
+              
+              
+              try
+              {
+                // determine whether this visit should be iterating.  If it shouldn't, don't
+                // even call the protected hook.  We currently don't iterate during the
+                // restore view phase when we are visiting all of the components.
+                boolean noIterate = (visitContext.getIdsToVisit() == VisitContext.ALL_IDS) &&
+                                    (context.getCurrentPhaseId() == PhaseId.RESTORE_VIEW);
+                  
+                doneVisiting =  (noIterate)
+                                  ? uixComponent._visitAllChildren(visitContext, callback)
+                                  : uixComponent.visitChildren(visitContext, callback);
+              }
+              finally
+              {
+                // teardown any context initialized above
+                if (rc != null)
+                {
+                  uixComponent._tearDownChildrenEncodingContext(context, rc);
+                }
+                else
+                {
+                  uixComponent.tearDownChildrenVisitingContext(context);
+                }
               }
             }
           }
+          else
+          {
+            // don't visit the children
+            assert(visitResult == VisitResult.REJECT);
+          }
         }
-        else
-        {
-          // don't visit the children
-          assert(visitResult == VisitResult.REJECT);
+        finally
+        {  
+         // tear down the context we set up in order to visit our component
+          if (rc != null)
+          {
+            uixComponent.tearDownEncodingContext(context, rc);
+          }
+          else
+          {
+            uixComponent.tearDownVisitingContext(context);
+          }
         }
       }
       finally
       {
-        // tear down the context we set up in order to visit our component
-        if (rc != null)
-        {
-          uixComponent.tearDownEncodingContext(context, rc);
-        }
-        else
-        {
-          uixComponent.tearDownVisitingContext(context);
-        }
+        component.popComponentFromEL(context);        
       }
-    
+      
       // if we got this far, we're not done
       return doneVisiting;
     }

Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java?rev=919945&r1=919944&r2=919945&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java (original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java Sun Mar  7 07:35:56 2010
@@ -1607,8 +1607,18 @@
 
     if (clientId.equals(thisClientId))
     {
-      // this is the component we want, so invoke the callback
-      callback.invokeContextCallback(context, this);
+      pushComponentToEL(context, null);
+      
+      try
+      {
+        // this is the component we want, so invoke the callback
+        callback.invokeContextCallback(context, this);
+      }
+      finally
+      {
+        popComponentFromEL(context);
+      }
+
       return true;
     }
     else
@@ -1659,7 +1669,18 @@
 
     if (clientId.equals(thisClientId))
     {
-      callback.invokeContextCallback(context, this);
+      pushComponentToEL(context, null);
+      
+      try
+      {
+        // this is the component we want, so invoke the callback
+        callback.invokeContextCallback(context, this);
+      }
+      finally
+      {
+        popComponentFromEL(context);
+      }
+
       return true;
     }
     else