myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bsulli...@apache.org
Subject svn commit: r921543 - 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/
Date Wed, 10 Mar 2010 20:09:00 GMT
Author: bsullivan
Date: Wed Mar 10 20:08:59 2010
New Revision: 921543

URL: http://svn.apache.org/viewvc?rev=921543&view=rev
Log:
Add setup/tearDownChildrenVisitingContext support for invokeOnComoponent and processFlattenedChildren

Modified:
    myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXGroupTemplate.java
    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-templates/org/apache/myfaces/trinidad/component/UIXSwitcherTemplate.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/UIXGroupTemplate.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/UIXGroupTemplate.java?rev=921543&r1=921542&r2=921543&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXGroupTemplate.java
(original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXGroupTemplate.java
Wed Mar 10 20:08:59 2010
@@ -58,12 +58,30 @@ abstract public class UIXGroupTemplate e
     
     try
     {
-      // bump up the group depth and render all of the children
-      return UIXComponent.processFlattenedChildren(context,
-                                                   cpContext,
-                                                   childProcessor,
-                                                   this.getChildren(),
-                                                   callBackContext);
+      setupVisitingContext(context);
+      
+      try
+      {
+        setupChildrenVisitingContext(context);
+        
+        try
+        {
+          // bump up the group depth and render all of the children
+          return UIXComponent.processFlattenedChildren(context,
+                                                       cpContext,
+                                                       childProcessor,
+                                                       this.getChildren(),
+                                                       callBackContext);
+        }
+        finally
+        {
+          tearDownChildrenVisitingContext(context);
+        }
+      }
+      finally
+      {
+        tearDownVisitingContext(context);
+      }
     }
     finally
     {

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=921543&r1=921542&r2=921543&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
Wed Mar 10 20:08:59 2010
@@ -78,36 +78,57 @@ public abstract class UIXIteratorTemplat
     final ComponentProcessor<S> childProcessor,
     final S callbackContext) throws IOException
   {
-    // Mimic what would normally happen in the non-flattening case for encodeBegin():
-    __processFlattenedChildrenBegin();
+    boolean processedChildren;
 
-    Runner runner = new IndexedRunner(cpContext)
+    setupVisitingContext(context);
+    
+    try
     {
-      @Override
-      protected void process(UIComponent kid, ComponentProcessingContext cpContext) throws
IOException
+      // Mimic what would normally happen in the non-flattening case for encodeBegin():
+      __processFlattenedChildrenBegin();
+  
+      setupChildrenVisitingContext(context);
+      
+      try
       {
-        kid.pushComponentToEL(context, null);
-
-        try
+        Runner runner = new IndexedRunner(cpContext)
         {
-          childProcessor.processComponent(context, cpContext, kid, callbackContext);
-        }
-        finally
+          @Override
+          protected void process(UIComponent kid, ComponentProcessingContext cpContext) throws
IOException
+          {
+            kid.pushComponentToEL(context, null);
+    
+            try
+            {
+              childProcessor.processComponent(context, cpContext, kid, callbackContext);
+            }
+            finally
+            {
+              kid.popComponentFromEL(context);         
+            }
+          }
+        };
+        
+        processedChildren = runner.run();
+        Exception exp = runner.getException();
+        if (exp != null)
         {
-          kid.popComponentFromEL(context);         
+          if (exp instanceof RuntimeException)
+            throw (RuntimeException) exp;
+    
+          if (exp instanceof IOException)
+            throw (IOException) exp;
+          throw new IllegalStateException(exp);
         }
       }
-    };
-    boolean processedChildren = runner.run();
-    Exception exp = runner.getException();
-    if (exp != null)
-    {
-      if (exp instanceof RuntimeException)
-        throw (RuntimeException) exp;
-
-      if (exp instanceof IOException)
-        throw (IOException) exp;
-      throw new IllegalStateException(exp);
+      finally
+      {
+        tearDownChildrenVisitingContext(context);
+      }
+    }
+    finally
+    {
+      tearDownVisitingContext(context);
     }
     
     return processedChildren;

Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXSwitcherTemplate.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/UIXSwitcherTemplate.java?rev=921543&r1=921542&r2=921543&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXSwitcherTemplate.java
(original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXSwitcherTemplate.java
Wed Mar 10 20:08:59 2010
@@ -78,16 +78,42 @@ abstract public class UIXSwitcherTemplat
     final ComponentProcessor<S> childProcessor,
     final S callbackContext) throws IOException
   {
-    UIComponent facet = _getFacet();
+    setupVisitingContext(context);
+   
+    boolean abort;
     
-    if (facet != null)
-      return UIXComponent.processFlattenedChildren(context,
-                                                   cpContext,
-                                                   childProcessor,
-                                                   facet,
-                                                   callbackContext);
-    else
-      return false;
+    try
+    {
+      UIComponent facet = _getFacet();
+      
+      if (facet != null)
+      {
+        setupChildrenVisitingContext(context);
+        
+        try
+        {
+          abort = UIXComponent.processFlattenedChildren(context,
+                                                        cpContext,
+                                                        childProcessor,
+                                                        facet,
+                                                        callbackContext);
+        }
+        finally
+        {
+          tearDownChildrenVisitingContext(context);
+        }
+      } 
+      else
+      {
+        abort = false;
+      }
+    }
+    finally
+    {
+      tearDownChildrenVisitingContext(context);
+    }
+    
+    return abort;
   }
 
   /**

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=921543&r1=921542&r2=921543&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
Wed Mar 10 20:08:59 2010
@@ -1083,88 +1083,100 @@ public abstract class UIXCollection exte
                                    ContextCallback callback)
     throws FacesException
   {
-    String thisClientId = getClientId(context);
-    if (clientId.equals(thisClientId))
-    {
-      if (!_getAndMarkFirstInvokeForRequest(context, clientId))
-      {
-        // Call _init() since _flushCachedModel() assumes that
-        // selectedRowKeys and disclosedRowKeys are initialized to be non-null
-        _init();
-
-        _flushCachedModel();
-      }
+    boolean invokedComponent;
 
-      pushComponentToEL(context, null);
-      
-      try
-      {
-        callback.invokeContextCallback(context, this);
-      }
-      finally
-      {
-        popComponentFromEL(context);
-      }
-      
-      return true;
-    }
-    // If we're on a row, set the currency, and invoke
-    // inside
-    int thisClientIdLength = thisClientId.length();
-    if (clientId.startsWith(thisClientId) &&
-        (clientId.charAt(thisClientIdLength) == NamingContainer.SEPARATOR_CHAR))
+    setupVisitingContext(context);
+    
+    try
     {
-      setupVisitingContext(context);
-
-      try
+      String thisClientId = getClientId(context);
+      if (clientId.equals(thisClientId))
       {
-        if (!_getAndMarkFirstInvokeForRequest(context, thisClientId))
+        if (!_getAndMarkFirstInvokeForRequest(context, clientId))
         {
           // Call _init() since _flushCachedModel() assumes that
           // selectedRowKeys and disclosedRowKeys are initialized to be non-null
           _init();
-
+  
           _flushCachedModel();
         }
-
-        String postId = clientId.substring(thisClientIdLength + 1);
-        int sepIndex = postId.indexOf(NamingContainer.SEPARATOR_CHAR);
-        // If there's no separator character afterwards, then this
-        // isn't a row key
-        if (sepIndex < 0)
-          return invokeOnChildrenComponents(context, clientId, callback);
-        else
+  
+        pushComponentToEL(context, null);
+        
+        try
         {
-          String currencyString = postId.substring(0, sepIndex);
-          Object rowKey = getClientRowKeyManager().getRowKey(context, this, currencyString);
-
-          // A non-null rowKey here means we are on a row and we should set currency,  otherwise
-          // the client id is for a non-stamped child component in the table/column header/footer.
-          if (rowKey != null)
+          callback.invokeContextCallback(context, this);
+        }
+        finally
+        {
+          popComponentFromEL(context);
+        }
+        
+        invokedComponent = true;
+      }
+      else
+      {
+        // If we're on a row, set the currency, and invoke
+        // inside
+        int thisClientIdLength = thisClientId.length();
+        if (clientId.startsWith(thisClientId) &&
+            (clientId.charAt(thisClientIdLength) == NamingContainer.SEPARATOR_CHAR))
+        {    
+          if (!_getAndMarkFirstInvokeForRequest(context, thisClientId))
+          {
+            // Call _init() since _flushCachedModel() assumes that
+            // selectedRowKeys and disclosedRowKeys are initialized to be non-null
+            _init();
+  
+            _flushCachedModel();
+          }
+  
+          String postId = clientId.substring(thisClientIdLength + 1);
+          int sepIndex = postId.indexOf(NamingContainer.SEPARATOR_CHAR);
+          // If there's no separator character afterwards, then this
+          // isn't a row key
+          if (sepIndex < 0)
+            return invokeOnChildrenComponents(context, clientId, callback);
+          else
           {
-            Object oldRowKey = getRowKey();
-            try
+            String currencyString = postId.substring(0, sepIndex);
+            Object rowKey = getClientRowKeyManager().getRowKey(context, this, currencyString);
+  
+            // A non-null rowKey here means we are on a row and we should set currency, 
otherwise
+            // the client id is for a non-stamped child component in the table/column header/footer.
+            if (rowKey != null)
             {
-              setRowKey(rowKey);
-              return invokeOnChildrenComponents(context, clientId, callback);
+              Object oldRowKey = getRowKey();
+              try
+              {
+                setRowKey(rowKey);
+                invokedComponent = invokeOnChildrenComponents(context, clientId, callback);
+              }
+              finally
+              {
+                // And restore the currency
+                setRowKey(oldRowKey);
+              }
             }
-            finally
+            else
             {
-              // And restore the currency
-              setRowKey(oldRowKey);
+              invokedComponent = invokeOnChildrenComponents(context, clientId, callback);
             }
           }
-          else
-            return invokeOnChildrenComponents(context, clientId, callback);
         }
-      }
-      finally
-      {
-        tearDownVisitingContext(context);
+        else
+        {
+          // clientId isn't in this subtree
+          invokedComponent = false;
+        }
       }
     }
-
-    return false;
+    finally
+    {
+      tearDownVisitingContext(context);
+    }
+    
+    return invokedComponent;
   }
 
   /**

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=921543&r1=921542&r2=921543&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
Wed Mar 10 20:08:59 2010
@@ -490,7 +490,7 @@ abstract public class UIXComponent exten
               // to the component itself
               if (rc != null)
               {
-                uixComponent._setupChildrenEncodingContext(context, rc);
+                uixComponent.setupChildrenEncodingContext(context, rc);
               }
               else
               {
@@ -515,7 +515,7 @@ abstract public class UIXComponent exten
                 // teardown any context initialized above
                 if (rc != null)
                 {
-                  uixComponent._tearDownChildrenEncodingContext(context, rc);
+                  uixComponent.tearDownChildrenEncodingContext(context, rc);
                 }
                 else
                 {
@@ -823,7 +823,7 @@ abstract public class UIXComponent exten
    * @see #setupVisitingContext
    * @see #tearDownVisitingContext
    * @see #tearDownEncodingContext
-   * @see CoreRenderer#setupEncodingContext
+   * @see org.apache.myfaces.trinidad.render.CoreRenderer#setupEncodingContext(FacesContext,
RenderingContext, UIComponent)
    */
   protected void setupEncodingContext(FacesContext context, RenderingContext rc)
   {
@@ -844,10 +844,10 @@ abstract public class UIXComponent exten
    * @param context The FacesContext
    * @param rc      RenderingContext to use for encoding
    * @see #setupChildrenVisitingContext
-   * @see #_tearDownChildrenEncodingContext
+   * @see #tearDownChildrenEncodingContext
    * @see org.apache.myfaces.trinidad.render.CoreRenderer#setupChildrenEncodingContext
    */
-  private void _setupChildrenEncodingContext(FacesContext context, RenderingContext rc)
+  protected void setupChildrenEncodingContext(FacesContext context, RenderingContext rc)
   {
     setupChildrenVisitingContext(context);
 
@@ -875,7 +875,7 @@ abstract public class UIXComponent exten
    * @see #setupEncodingContext
    * @see #tearDownVisitingContext
    * @see #setupEncodingContext
-   * @see CoreRenderer#tearDownEncodingContext
+   * @see org.apache.myfaces.trinidad.render.CoreRenderer#tearDownEncodingContext(FacesContext,
RenderingContext, UIComponent)
    */
   protected void tearDownEncodingContext(
     FacesContext context,
@@ -903,10 +903,10 @@ abstract public class UIXComponent exten
    * @param context The FacesContext
    * @param rc      RenderingContext to use for encoding
    * @see #setupChildrenVisitingContext
-   * @see #_tearDownChildrenEncodingContext
+   * @see #setupChildrenEncodingContext
    * @see org.apache.myfaces.trinidad.render.CoreRenderer#setupChildrenEncodingContext
    */
-  private void _tearDownChildrenEncodingContext(
+  protected void tearDownChildrenEncodingContext(
     FacesContext context,
     RenderingContext rc)
   {

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=921543&r1=921542&r2=921543&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
Wed Mar 10 20:08:59 2010
@@ -1565,8 +1565,12 @@ abstract public class UIXComponentBase e
 
   /**
    * Convenience method to call <code>invokeOnComponent</code> on all of the
-   * children of a component.  This is useful when a component sometimes optimizes
-   * away calling <code>invokeOnComponent</code> on its children
+   * children of a component, surrounding the invocation with calls to
+   * <code>setup/tearDownChildrenVisitingContext</code>.
+   * This is useful when a component sometimes optimizes
+   * away calling <code>invokeOnComponent</code> on its children.
+   * @see UIXComponent#setupChildrenVisitingContext
+   * @see UIXComponent#tearDownChildrenVisitingContext
    */
   protected final boolean invokeOnChildrenComponents(
     FacesContext context,
@@ -1574,15 +1578,25 @@ abstract public class UIXComponentBase e
     ContextCallback callback)
     throws FacesException
   {
-    Iterator<UIComponent> children = getFacetsAndChildren();
+    setupChildrenVisitingContext(context);
 
     boolean found = false;
 
-    while (children.hasNext() && !found)
+    try
     {
-      found = children.next().invokeOnComponent(context, clientId, callback);
+      Iterator<UIComponent> children = getFacetsAndChildren();
+  
+  
+      while (children.hasNext() && !found)
+      {
+        found = children.next().invokeOnComponent(context, clientId, callback);
+      }
     }
-
+    finally
+    {
+      tearDownChildrenVisitingContext(context);
+    }
+    
     return found;
   }
 
@@ -1593,7 +1607,7 @@ abstract public class UIXComponentBase e
    * NamingContainer's children is skipped.
    * </p>
    * <p>Subclasses implementing NamingContainer should override
-   * <code>invokeOnComponent</code> and delegate to this method.</p>
+   * <code>invokeOnComponent</code> and delegate to this method.
    */
   protected final boolean invokeOnNamingContainerComponent(
     FacesContext context,
@@ -1603,53 +1617,54 @@ abstract public class UIXComponentBase e
   {
     assert this instanceof NamingContainer : "Only use invokeOnNamingContainerComponent on
NamingContainers";
 
-    String thisClientId = getClientId(context);
+    boolean invokedComponent;
 
-    if (clientId.equals(thisClientId))
+    setupVisitingContext(context);
+    
+    try
     {
-      pushComponentToEL(context, null);
-      
-      try
+      String thisClientId = getClientId(context);
+  
+      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);
+        }
+  
+        invokedComponent = true;
       }
-      finally
+      else
       {
-        popComponentFromEL(context);
+        // if this is a NamingContainer, only traverse into it if the clientId we are looking
for
+        // is inside of it
+        if ((!clientId.startsWith(thisClientId) ||
+            (clientId.charAt(thisClientId.length()) != NamingContainer.SEPARATOR_CHAR)))
+        {
+          invokedComponent = false;
+        }
+        else
+        {
+          // setup the children visiting context and iterate through children.
+          // We inline this code instead of calling super in order
+          // to avoid making an extra call to getClientId().
+          invokedComponent = invokeOnChildrenComponents(context, clientId, callback);
+        }
       }
-
-      return true;
     }
-    else
+    finally
     {
-      // if this is a NamingContainer, only traverse into it if the clientId we are looking
for
-      // is inside of it
-      if ((!clientId.startsWith(thisClientId) ||
-          (clientId.charAt(thisClientId.length()) != NamingContainer.SEPARATOR_CHAR)))
-      {
-        return false;
-      }
-
-      boolean invokedComponent = false;
-
-      // set up the context for visiting the children
-      setupVisitingContext(context);
-
-      try
-      {
-        // iterate through children. We inline this code instead of calling super in order
-        // to avoid making an extra call to getClientId().
-        invokedComponent = invokeOnChildrenComponents(context, clientId, callback);
-      }
-      finally
-      {
-        // teardown the context now that we have visited the children
-        tearDownVisitingContext(context);
-      }
-
-      return invokedComponent;
+      tearDownVisitingContext(context);
     }
+
+    return invokedComponent;
   }
 
   /**
@@ -1665,45 +1680,47 @@ abstract public class UIXComponentBase e
     ContextCallback callback)
     throws FacesException
   {
-    String thisClientId = getClientId(context);
+    boolean invokedComponent;
+    
+    // set up the context for visiting the children
+    setupVisitingContext(context);
 
-    if (clientId.equals(thisClientId))
+    try
     {
-      pushComponentToEL(context, null);
-      
-      try
-      {
-        // this is the component we want, so invoke the callback
-        callback.invokeContextCallback(context, this);
-      }
-      finally
+      String thisClientId = getClientId(context);
+  
+      if (clientId.equals(thisClientId))
       {
-        popComponentFromEL(context);
+        pushComponentToEL(context, null);
+        
+        try
+        {
+          // this is the component we want, so invoke the callback
+          callback.invokeContextCallback(context, this);
+        }
+        finally
+        {
+          popComponentFromEL(context);
+        }
+  
+        // we found the component
+        invokedComponent = true;
       }
-
-      return true;
-    }
-    else
-    {
-      boolean invokedComponent = false;
-
-      // set up the context for visiting the children
-      setupVisitingContext(context);
-
-      try
+      else
       {
-        // iterate through children. We inline this code instead of calling super in order
+        // set up the children visiting context to iterate through children. We inline this
+        // code instead of calling super in order
         // to avoid making an extra call to getClientId().
         invokedComponent = invokeOnChildrenComponents(context, clientId, callback);
       }
-      finally
-      {
-        // teardown the context now that we have visited the children
-        tearDownVisitingContext(context);
-      }
-
-      return invokedComponent;
     }
+    finally
+    {
+      // teardown the context now that we have visited the component
+      tearDownVisitingContext(context);      
+    }
+    
+    return invokedComponent;
   }
 
   // ------------------------- Client behavior holder methods -------------------------



Mime
View raw message