You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by an...@apache.org on 2011/03/11 16:17:43 UTC

svn commit: r1080600 - /myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ComponentUtils.java

Author: andys
Date: Fri Mar 11 15:17:43 2011
New Revision: 1080600

URL: http://svn.apache.org/viewvc?rev=1080600&view=rev
Log:
TRINIDAD-2056 Add utility method for locating nearest non-flattening ancestor component

Added ComponentUtils.getNonFlatteningAncestor() API.

Modified:
    myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ComponentUtils.java

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ComponentUtils.java?rev=1080600&r1=1080599&r2=1080600&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ComponentUtils.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ComponentUtils.java Fri Mar 11 15:17:43 2011
@@ -27,6 +27,9 @@ import javax.faces.component.UIComponent
 
 import javax.faces.component.UIViewRoot;
 
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.trinidad.component.FlattenedComponent;
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 
 /**
@@ -467,6 +470,40 @@ public final class ComponentUtils
     
     return builder.toString();
   }
+
+  /**
+   * Returns the nearest ancestor component, skipping over any
+   * flattening components.
+   * 
+   * @param context the FacesContext
+   * @param component the UIComponent
+   * @return the first ancestor component that is not a FlattenedComponent
+   *   that is actively flattening its children or null if no such ancestor
+   *   component is found.
+   * @see org.apache.myfaces.trinidad.component.FlattenedComponent
+   */
+  public static UIComponent getNonFlatteningAncestor(
+    FacesContext context,
+    UIComponent component)
+  {
+    UIComponent parent = component.getParent();
+    
+    while (parent != null)
+    { 
+      if (!_isFlattening(context, parent))
+        return parent;
+      
+      parent = parent.getParent();
+    }
+
+    return null;
+  }
+
+  private static boolean _isFlattening(FacesContext context, UIComponent component)
+  {
+    return ((component instanceof FlattenedComponent) &&
+      ((FlattenedComponent)component).isFlatteningChildren(context));
+  }
   
   /**
    * Builds the scoped id. Adds the naming container's id and the separator char