You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ar...@apache.org on 2010/08/24 18:33:13 UTC

svn commit: r988615 - in /myfaces/trinidad/branches/trinidad-1.2.x: ./ trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/ trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/core/layout/ trinidad-api/src/...

Author: arobinson74
Date: Tue Aug 24 16:33:13 2010
New Revision: 988615

URL: http://svn.apache.org/viewvc?rev=988615&view=rev
Log:
TRINIDAD-1884 back port tree visiting changes from Trinidad 2 to 1.2

Added:
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/visit/VisitContextWrapper.java
      - copied unchanged from r988607, myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/visit/VisitContextWrapper.java
Modified:
    myfaces/trinidad/branches/trinidad-1.2.x/   (props changed)
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXGroupTemplate.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXIteratorTemplate.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXNavigationLevelTemplate.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXNavigationPathTemplate.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXPageTemplate.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXShowDetailTemplate.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXShowOneTemplate.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXSwitcherTemplate.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/core/layout/CorePanelAccordionTemplate.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java

Propchange: myfaces/trinidad/branches/trinidad-1.2.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug 24 16:33:13 2010
@@ -3,5 +3,9 @@
 /myfaces/trinidad/branches/1.2.12.2-branch:888969
 /myfaces/trinidad/branches/1.2.9.1-branch:697924,699406,699496
 /myfaces/trinidad/branches/TRINIDAD-1402:745675
+/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree:964963-966042
+/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_2:966043-984257
+/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_3:984258-984269
+/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree_4:984270-988607
 /myfaces/trinidad/branches/jwaldman_StyleMap:754977-770778
 /myfaces/trinidad/trunk:930425,932153

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXGroupTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXGroupTemplate.java?rev=988615&r1=988614&r2=988615&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXGroupTemplate.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXGroupTemplate.java Tue Aug 24 16:33:13 2010
@@ -19,6 +19,7 @@
 package org.apache.myfaces.trinidad.component;
 
 import java.io.IOException;
+
 import java.util.List;
 
 import javax.faces.component.UIComponent;
@@ -58,6 +59,14 @@ abstract public class UIXGroupTemplate e
     
     try
     {
+      setupVisitingContext(context);
+
+      try
+      {
+        setupChildrenVisitingContext(context);
+
+        try
+        {
       // bump up the group depth and render all of the children
       return UIXComponent.processFlattenedChildren(context,
                                                    cpContext,
@@ -67,6 +76,16 @@ abstract public class UIXGroupTemplate e
     }
     finally
     {
+          tearDownChildrenVisitingContext(context);
+        }
+      }
+      finally
+      {
+        tearDownVisitingContext(context);
+      }
+    }
+    finally
+    {
       cpContext.popGroup();      
     }
   }

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXIteratorTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXIteratorTemplate.java?rev=988615&r1=988614&r2=988615&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXIteratorTemplate.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXIteratorTemplate.java Tue Aug 24 16:33:13 2010
@@ -40,6 +40,7 @@ import org.apache.myfaces.trinidad.compo
 import org.apache.myfaces.trinidad.model.CollectionModel;
 import org.apache.myfaces.trinidad.model.LocalRowKeyIndex;
 import org.apache.myfaces.trinidad.model.ModelUtils;
+import org.apache.myfaces.trinidad.render.ClientRowKeyManager;
 
 import org.apache.myfaces.trinidad.render.ClientRowKeyManager;
 
@@ -76,27 +77,52 @@ 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;
+
+    setupVisitingContext(context);
 
-    Runner runner = new IndexedRunner(cpContext)
+    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
+      {
+        Runner runner = new IndexedRunner(cpContext)
+        {
+          @Override
+          protected void process(
+            UIComponent                kid,
+            ComponentProcessingContext cpContext
+            ) throws IOException
+            {
+              childProcessor.processComponent(context, cpContext, kid, callbackContext);
+            }
+        };
+
+        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
       {
-        childProcessor.processComponent(context, cpContext, kid, callbackContext);
+        tearDownChildrenVisitingContext(context);
       }
-    };
-    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
+    {
+      tearDownVisitingContext(context);
     }
     
     return processedChildren;

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXNavigationLevelTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXNavigationLevelTemplate.java?rev=988615&r1=988614&r2=988615&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXNavigationLevelTemplate.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXNavigationLevelTemplate.java Tue Aug 24 16:33:13 2010
@@ -31,7 +31,8 @@ import org.apache.myfaces.trinidad.compo
  *
  * @version $Name:  $ ($Revision$) $Date$
  */
-abstract public class UIXNavigationLevelTemplate extends UIXNavigationHierarchy
+abstract public class UIXNavigationLevelTemplate
+  extends UIXNavigationHierarchy
 {
 /**/ // Abstract methods implemented by code gen
 /**/  abstract public int getLevel();

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXNavigationPathTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXNavigationPathTemplate.java?rev=988615&r1=988614&r2=988615&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXNavigationPathTemplate.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXNavigationPathTemplate.java Tue Aug 24 16:33:13 2010
@@ -34,9 +34,9 @@ import org.apache.myfaces.trinidad.compo
  *
  * @version $Name:  $ ($Revision$) $Date$
  */
-abstract public class UIXNavigationPathTemplate extends UIXNavigationHierarchy
+abstract public class UIXNavigationPathTemplate
+  extends UIXNavigationHierarchy
 {
-	
   @Override
   protected void processFacetsAndChildren(
     FacesContext context,

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXPageTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXPageTemplate.java?rev=988615&r1=988614&r2=988615&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXPageTemplate.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXPageTemplate.java Tue Aug 24 16:33:13 2010
@@ -51,6 +51,7 @@ abstract public class UIXPageTemplate ex
 /**/  public abstract void setDisclosedRowKeys(RowKeySet state);
 /**/  public abstract MethodBinding getRowDisclosureListener();
 /**/  static public final PropertyKey DISCLOSED_ROW_KEYS_KEY = null;
+/**/  public abstract UIComponent getNodeStamp();
 
   /**
    * Sets the phaseID of UI events depending on the "immediate" property.

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXShowDetailTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXShowDetailTemplate.java?rev=988615&r1=988614&r2=988615&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXShowDetailTemplate.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXShowDetailTemplate.java Tue Aug 24 16:33:13 2010
@@ -25,6 +25,9 @@ import javax.faces.event.AbortProcessing
 import javax.faces.event.FacesEvent;
 import javax.faces.event.PhaseId;
 
+import org.apache.myfaces.trinidad.component.visit.VisitCallback;
+import org.apache.myfaces.trinidad.component.visit.VisitContext;
+import org.apache.myfaces.trinidad.component.visit.VisitHint;
 import org.apache.myfaces.trinidad.event.DisclosureEvent;
 
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
@@ -133,5 +136,16 @@ abstract public class UIXShowDetailTempl
     super.queueEvent(e);
   }
 
+  @Override
+  protected boolean visitChildren(
+    VisitContext  visitContext,
+    VisitCallback callback)
+  {
+    return
+      (visitContext.getHints().contains(VisitHint.SKIP_UNRENDERED) == false ||
+        this.isDisclosed()) &&
+      super.visitChildren(visitContext, callback);
+  }
+
   static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(UIXShowDetail.class);
 }

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXShowOneTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXShowOneTemplate.java?rev=988615&r1=988614&r2=988615&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXShowOneTemplate.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXShowOneTemplate.java Tue Aug 24 16:33:13 2010
@@ -19,22 +19,27 @@
 package org.apache.myfaces.trinidad.component;
 
 import java.io.IOException;
-import java.util.List;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.event.FacesEvent;
 import javax.faces.event.PhaseId;
 
+import org.apache.myfaces.trinidad.component.visit.VisitCallback;
+import org.apache.myfaces.trinidad.component.visit.VisitContext;
+import org.apache.myfaces.trinidad.component.visit.VisitContextWrapper;
+import org.apache.myfaces.trinidad.component.visit.VisitHint;
+import org.apache.myfaces.trinidad.component.visit.VisitResult;
 import org.apache.myfaces.trinidad.event.DisclosureEvent;
 
+
 /**
  * Base class for ShowOne component.
  * @version $Name:  $ ($Revision$) $Date$
  */
-abstract public class UIXShowOneTemplate extends UIXComponentBase
+abstract public class UIXShowOneTemplate
+  extends UIXComponentBase
 {
-	
   @Override
   @SuppressWarnings("unchecked")
   public void queueEvent(FacesEvent e)
@@ -85,6 +90,26 @@ abstract public class UIXShowOneTemplate
     super.queueEvent(e);
   }
 
+  @Override
+  public boolean visitTree(
+    VisitContext  visitContext,
+    VisitCallback callback)
+  {
+    if (visitContext.getHints().contains(VisitHint.SKIP_UNRENDERED))
+    {
+      // Filter which children to be visited so that only one show detail
+      // is visited for this show one component
+      visitContext = new PartialVisitContext(visitContext);
+    }
+    return super.visitTree(visitContext, callback);
+  }
+
+  protected boolean isChildSelected(
+    UIXShowDetail component)
+  {
+    return component.isDisclosed();
+  }
+
   /**
    * State passed to the UndisclosureCallback.
    */
@@ -145,5 +170,70 @@ abstract public class UIXShowOneTemplate
     }
   }
 
+  private class PartialVisitContext
+    extends VisitContextWrapper
+  {
+    PartialVisitContext(VisitContext wrapped)
+    {
+      _wrapped = wrapped;
+    }
+
+    public VisitContext getWrapped()
+    {
+      return _wrapped;
+    }
+
+    @Override
+    public VisitResult invokeVisitCallback(
+      UIComponent   component,
+      VisitCallback visitCallback)
+    {
+      if (component instanceof UIXShowDetail)
+      {
+        UIXShowDetail showDetail = (UIXShowDetail)component;
+        if (_isShowDetailForCurrentComponent(showDetail))
+        {
+          if (_foundItemToRender || !isChildSelected(showDetail))
+          {
+            // We already visited the one to be shown
+            return VisitResult.REJECT;
+          }
+          else
+          {
+            _foundItemToRender = true;
+          }
+        }
+      }
+
+      return super.invokeVisitCallback(component, visitCallback);
+    }
+
+    private boolean _isShowDetailForCurrentComponent(
+      UIXShowDetail showDetail)
+    {
+      for (UIComponent parent = showDetail.getParent(); parent != null; parent = parent.getParent())
+      {
+        if (parent == UIXShowOne.this)
+        {
+          return true;
+        }
+
+        if (parent instanceof FlattenedComponent &&
+          ((FlattenedComponent)parent).isFlatteningChildren(getFacesContext()))
+        {
+          continue;
+        }
+
+        // The first-non flattened component is not the show one, do not filter it
+        return false;
+      }
+
+      return false;
+    }
+
+    private boolean      _foundItemToRender;
+    private VisitContext _wrapped;
+  }
+
   private final UndisclosureCallback _undisclosureCallback = new UndisclosureCallback();
 }

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXSwitcherTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXSwitcherTemplate.java?rev=988615&r1=988614&r2=988615&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXSwitcherTemplate.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXSwitcherTemplate.java Tue Aug 24 16:33:13 2010
@@ -23,6 +23,10 @@ import java.io.IOException;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 
+import org.apache.myfaces.trinidad.component.visit.VisitCallback;
+import org.apache.myfaces.trinidad.component.visit.VisitContext;
+import org.apache.myfaces.trinidad.component.visit.VisitHint;
+
 
 /**
  * Base class for the switcher componnet.
@@ -57,7 +61,6 @@ abstract public class UIXSwitcherTemplat
       facet.processValidators(context);
   }
 
-
   /**
    * Only process updates on the currently active facet.
    */
@@ -78,17 +81,37 @@ abstract public class UIXSwitcherTemplat
     final ComponentProcessor<S> childProcessor,
     final S callbackContext) throws IOException
   {
+    setupVisitingContext(context);
+
     UIComponent facet = _getFacet();
     
+    try
+    {
     if (facet != null)
+      {
+        setupChildrenVisitingContext(context);
+        
+        try
+        {
       return UIXComponent.processFlattenedChildren(context,
                                                    cpContext,
                                                    childProcessor,
                                                    facet,
                                                    callbackContext);
+        }
+        finally
+        {
+          tearDownChildrenVisitingContext(context);
+        }
+      }      
     else
       return false;
   }
+    finally
+    {
+      tearDownChildrenVisitingContext(context);
+    }
+  }
 
   /**
    * Returns <code>true</code> if this FlattenedComponent is currently flattening its children
@@ -112,7 +135,6 @@ abstract public class UIXSwitcherTemplat
       __encodeRecursive(context, facet);
   }
 
-
   /**
    * Override to return true.
    */
@@ -122,6 +144,26 @@ abstract public class UIXSwitcherTemplat
     return true;
   }
 
+  @Override
+  protected boolean visitChildren(
+    VisitContext  visitContext,
+    VisitCallback callback)
+  {
+    if (visitContext.getHints().contains(VisitHint.SKIP_UNRENDERED))
+    {
+      UIComponent facet = _getFacet();
+      if (facet != null)
+      {
+        return UIXComponent.visitTree(visitContext, facet, callback);
+      }
+      return false;
+    }
+    else
+    {
+      return super.visitChildren(visitContext, callback);
+    }
+  }
+
   private UIComponent _getFacet()
   {
     if (!isRendered())
@@ -141,7 +183,6 @@ abstract public class UIXSwitcherTemplat
 
     return null;
   }
-
 }
 
 

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/core/layout/CorePanelAccordionTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/core/layout/CorePanelAccordionTemplate.java?rev=988615&r1=988614&r2=988615&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/core/layout/CorePanelAccordionTemplate.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/core/layout/CorePanelAccordionTemplate.java Tue Aug 24 16:33:13 2010
@@ -18,19 +18,28 @@
  */
 package org.apache.myfaces.trinidad.component.core.layout;
 
+import java.util.List;
+
 import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.el.MethodBinding;
 import javax.faces.event.AbortProcessingException;
 import javax.faces.event.FacesEvent;
-import javax.faces.event.PhaseId;
-import java.util.List;
 
-import org.apache.myfaces.trinidad.event.DisclosureEvent;
+import org.apache.myfaces.trinidad.component.FlattenedComponent;
+import org.apache.myfaces.trinidad.component.UIXPanel;
 import org.apache.myfaces.trinidad.component.UIXShowDetail;
+import org.apache.myfaces.trinidad.component.visit.VisitCallback;
+import org.apache.myfaces.trinidad.component.visit.VisitContext;
+import org.apache.myfaces.trinidad.component.visit.VisitContextWrapper;
+import org.apache.myfaces.trinidad.component.visit.VisitHint;
+import org.apache.myfaces.trinidad.component.visit.VisitResult;
+import org.apache.myfaces.trinidad.event.DisclosureEvent;
+
 
-abstract public class CorePanelAccordion extends UIXPanel
+abstract public class CorePanelAccordionTemplate
+  extends UIXPanel
 {
+/**/ public abstract boolean isDiscloseMany();
+
     /**
    * Queues an event recursively to the root component.
    * @param event
@@ -67,4 +76,91 @@ abstract public class CorePanelAccordion
     super.queueEvent(event);
   }
 
+  protected boolean isChildSelected(
+    UIXShowDetail component)
+  {
+    return component.isDisclosed();
+  }
+
+  @Override
+  public boolean visitTree(
+    VisitContext  visitContext,
+    VisitCallback callback)
+  {
+    if (visitContext.getHints().contains(VisitHint.SKIP_UNRENDERED) &&
+     !isDiscloseMany())
+    {
+      // Filter which children to be visited so that only one show detail
+      // is visited for this accordion
+      visitContext = new PartialVisitContext(visitContext);
+    }
+    return super.visitTree(visitContext, callback);
+  }
+
+  private class PartialVisitContext
+    extends VisitContextWrapper
+  {
+    PartialVisitContext(
+      VisitContext wrapped)
+    {
+      _wrapped = wrapped;
+    }
+
+    public VisitContext getWrapped()
+    {
+      return _wrapped;
+    }
+
+    @Override
+    public VisitResult invokeVisitCallback(
+      UIComponent   component,
+      VisitCallback visitCallback)
+    {
+      if (component instanceof UIXShowDetail)
+      {
+        UIXShowDetail showDetail = (UIXShowDetail)component;
+        if (_isShowDetailForCurrentComponent(showDetail))
+        {
+          if (_foundItemToRender || !isChildSelected(showDetail))
+          {
+            // We already visited the one to be shown
+            return VisitResult.REJECT;
+          }
+          else
+          {
+            _foundItemToRender = true;
+          }
+        }
+      }
+
+      return super.invokeVisitCallback(component, visitCallback);
+    }
+
+    private boolean _isShowDetailForCurrentComponent(
+      UIXShowDetail showDetail)
+    {
+      for (UIComponent parent = showDetail.getParent(); parent != null;
+           parent = parent.getParent())
+      {
+        if (parent == CorePanelAccordion.this)
+        {
+          return true;
+        }
+
+        if (parent instanceof FlattenedComponent &&
+          ((FlattenedComponent)parent).isFlatteningChildren(getFacesContext()))
+        {
+          continue;
+        }
+
+        // The first-non flattened component is not the show one, do not filter it
+        return false;
+      }
+
+      return false;
+    }
+
+    private boolean      _foundItemToRender;
+    private VisitContext _wrapped;
+  }
 }
\ No newline at end of file

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java?rev=988615&r1=988614&r2=988615&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java Tue Aug 24 16:33:13 2010
@@ -1014,12 +1014,13 @@ abstract public class UIXComponentBase e
     return getFacesBean().saveState(context);
   }
 
-  public void restoreState(FacesContext context, Object stateObj)
+  public void restoreState(
+    FacesContext facesContext,
+    Object       stateObj)
   {
-    getFacesBean().restoreState(context, stateObj);
+    getFacesBean().restoreState(facesContext, stateObj);
   }
 
-
   @Override
   public String toString()
   {
@@ -1385,8 +1386,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,
@@ -1394,13 +1399,22 @@ abstract public class UIXComponentBase e
     ContextCallback callback)
     throws FacesException
   {
-    Iterator<UIComponent> children = getFacetsAndChildren();
+    setupChildrenVisitingContext(context);
     
     boolean found = false;
     
-    while (children.hasNext() && !found)
+    try
+    {
+      Iterator<UIComponent> children = getFacetsAndChildren();
+
+      while (children.hasNext() && !found)
+      {
+        found = children.next().invokeOnComponent(context, clientId, callback);
+      }
+    }
+    finally
     {
-      found = children.next().invokeOnComponent(context, clientId, callback);
+      tearDownChildrenVisitingContext(context);
     }
     
     return found;
@@ -1423,43 +1437,45 @@ abstract public class UIXComponentBase e
   {
     assert this instanceof NamingContainer : "Only use invokeOnNamingContainerComponent on NamingContainers";
     
-    String thisClientId = getClientId(context);
+    boolean invokedComponent;
 
-    if (clientId.equals(thisClientId))
-    {
-      // this is the component we want, so invoke the callback
-      callback.invokeContextCallback(context, this);
-      return true;
-    }
-    else
+    setupVisitingContext(context);
+
+    try
     {
-      // 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;
-      }
+      String thisClientId = getClientId(context);
 
-      boolean invokedComponent = false;
-      
-      // set up the context for visiting the children
-      setupVisitingContext(context);
-            
-      try
+      if (clientId.equals(thisClientId))
       {
-        // 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);
+        // this is the component we want, so invoke the callback
+        callback.invokeContextCallback(context, this);
+        return true;
       }
-      finally
+      else
       {
-        // teardown the context now that we have visited the children
-        tearDownVisitingContext(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
+        {
+            // 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 invokedComponent;
     }
+    finally
+    {
+      // teardown the context now that we have visited the children
+      tearDownVisitingContext(context);
+    }
+      
+    return invokedComponent;
   }
   
   /**
@@ -1475,38 +1491,32 @@ abstract public class UIXComponentBase e
     ContextCallback callback)
     throws FacesException
   {
-    String thisClientId = getClientId(context);
+    // set up the context for visiting the children
+    setupVisitingContext(context);
 
-    if (clientId.equals(thisClientId))
-    {
-      callback.invokeContextCallback(context, this);
-      return true;
-    }
-    else
+    try
     {
-      boolean invokedComponent = false;
-      
-      // set up the context for visiting the children
-      setupVisitingContext(context);
-            
-      try
+      String thisClientId = getClientId(context);
+
+      if (clientId.equals(thisClientId))
       {
-        // 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);
+        callback.invokeContextCallback(context, this);
+        return true;
       }
-      finally
+      else
       {
-        // teardown the context now that we have visited the children
-        tearDownVisitingContext(context);
+          // iterate through children. We inline this code instead of calling super in order
+          // to avoid making an extra call to getClientId().
+          return invokeOnChildrenComponents(context, clientId, callback);
       }
-      
-      return invokedComponent;
+    }
+    finally
+    {
+      // teardown the context now that we have visited the children
+      tearDownVisitingContext(context);
     }
   }
 
-
-
   /**
    * <p>
    * This gets a single threadlocal shared stringbuilder instance, each time you call

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java?rev=988615&r1=988614&r2=988615&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java Tue Aug 24 16:33:13 2010
@@ -151,7 +151,7 @@ public class CoreRenderer extends Render
 
   /**
    * <p>
-   * Called after rendering the current component in order to tear
+   * Called after rendering the current component's children in order to tear
    * down any special context.
    * </p>
    * <p>
@@ -205,6 +205,47 @@ public class CoreRenderer extends Render
   {
   }
 
+  /**
+   * Hook to allow the renderer to customize the visitation of the children components
+   * of a component during the visitation of a component during rendering.
+   *
+   * @param component the component which owns the children to visit
+   * @param visitContext the visitation context
+   * @param callback the visit callback
+   * @return <code>true</code> if the visit is complete.
+   * @see UIXComponent#visitChildren(VisitContext, VisitCallback)
+   */
+  public boolean visitChildrenForEncoding(
+    UIXComponent  component,
+    VisitContext  visitContext,
+    VisitCallback callback)
+  {
+    // visit the children of the component
+    Iterator<UIComponent> kids = component.getFacetsAndChildren();
+
+    while (kids.hasNext())
+    {
+      // If any kid visit returns true, we are done.
+      UIComponent kid = kids.next();
+      if (kid instanceof UIXComponent)
+      {
+        if (((UIXComponent)kid).visitTree(visitContext, callback))
+        {
+          return true;
+        }
+      }
+      else
+      {
+        if (UIXComponent.visitTree(visitContext, kid, callback))
+        {
+          return true;
+        }
+      }
+    }
+
+    return false;
+  }
+
   //
   // COERCION HELPERS
   //