myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bsulli...@apache.org
Subject svn commit: r1291571 - /myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java
Date Tue, 21 Feb 2012 03:04:33 GMT
Author: bsullivan
Date: Tue Feb 21 03:04:33 2012
New Revision: 1291571

URL: http://svn.apache.org/viewvc?rev=1291571&view=rev
Log:
Changes for TRINIDAD-2221

Allow ancestor components to transform and filter ComponentChanges added by their descendants
as described in the JIRA

Modified:
    myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java?rev=1291571&r1=1291570&r2=1291571&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java
(original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java
Tue Feb 21 03:04:33 2012
@@ -71,16 +71,15 @@ import org.apache.myfaces.trinidad.bean.
 import org.apache.myfaces.trinidad.bean.util.StateUtils;
 import org.apache.myfaces.trinidad.bean.util.ValueMap;
 import org.apache.myfaces.trinidad.change.AttributeComponentChange;
+import org.apache.myfaces.trinidad.change.ComponentChange;
 import org.apache.myfaces.trinidad.change.RowKeySetAttributeChange;
 import org.apache.myfaces.trinidad.component.ComponentProcessingContext.ProcessingHint;
-import org.apache.myfaces.trinidad.component.UIXComponent;
 import org.apache.myfaces.trinidad.context.RenderingContext;
 import org.apache.myfaces.trinidad.context.RequestContext;
 import org.apache.myfaces.trinidad.event.AttributeChangeEvent;
 import org.apache.myfaces.trinidad.event.AttributeChangeListener;
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 import org.apache.myfaces.trinidad.model.RowKeySet;
-import org.apache.myfaces.trinidad.render.CoreRenderer;
 import org.apache.myfaces.trinidad.render.ExtendedRenderer;
 import org.apache.myfaces.trinidad.render.LifecycleRenderer;
 import org.apache.myfaces.trinidad.util.CollectionUtils;
@@ -1399,27 +1398,102 @@ abstract public class UIXComponentBase e
        getFacesBean().getEntries(_LISTENERS_KEY, clazz);
   }
 
-  protected void addAttributeChange(
-    String attributeName,
-    Object attributeValue)
+  /**
+   * Adds a change for a Component, or the Component's subtree, returning the change actually
added,
+   * or <code>null</code>, if no change was added.  The proposed change may be
rejected by the
+   * component itself, one of its ancestors, or the ChangeManager implementation.
+   * @param change     The change to add for this component
+   * @return The ComponentChange actually added, or
+   * <code>null</code> if no change was added.
+   * @see #addComponentChange(UIComponent, ComponentChange)
+   */
+  public final ComponentChange addComponentChange(ComponentChange change)
+  {
+    return addComponentChange(this, change);
+  }
+  
+  private UIXComponentBase _getNextUIXComponentBaseAnxcestor()
   {
-    AttributeComponentChange aa;
+    UIComponent parent = getParent();
 
-    FacesContext context = getFacesContext();
+    while (parent != null)
+    {    
+      if (parent instanceof UIXComponentBase)
+      {
+        return (UIXComponentBase)parent;
+      }
+      
+      parent = parent.getParent();
+    }
+    
+    return null;
+  }
 
-    if (attributeValue instanceof RowKeySet)
-    {
-      aa = new RowKeySetAttributeChange(getClientId(context),
-                                        attributeName,
-                                        attributeValue);
+  /**
+   * Called when adding a change to a Component, or the Component's subtree.
+   * The default implementation delegates the call to the parent, if possible, otherwise
+   * it adds the change to the ChangeManager directly.
+   * Subclasses can override this method to among other things, filter or transform the changes.
+   * @param component  The component that the change is for
+   * @param change     The change to add for this component
+   * @return The ComponentChange actually added, or
+   * <code>null</code> if no change was added.
+   * @see #addComponentChange(ComponentChange)
+   * @see #addAttributeChange
+   */
+  protected ComponentChange addComponentChange(UIComponent component, ComponentChange change)
+  {
+    // check moved from addAttributeChange(), as this is more central
+    if ((component == this) && (change instanceof AttributeComponentChange))
+    {
+      AttributeComponentChange aa             = (AttributeComponentChange)change;
+      Object                   attributeValue = aa.getAttributeValue();
+      
+      if (attributeValue instanceof RowKeySet)
+      {
+        change = new RowKeySetAttributeChange(getClientId(getFacesContext()),
+                                              aa.getAttributeName(),
+                                              attributeValue);
+      }
+    }
+    
+    // add the change unless changes for this subtree have suppressed
+    if (!Boolean.TRUE.equals(getAttributes().get(_NO_SUBTREE_CHANGE_ATTR)))
+    {
+      UIXComponentBase nextUIXParent = _getNextUIXComponentBaseAnxcestor();
+  
+      if (nextUIXParent != null)
+      {
+        return nextUIXParent.addComponentChange(component, change);
+      }
+      else
+      {
+        RequestContext trinContext = RequestContext.getCurrentInstance();
+        trinContext.getChangeManager().addComponentChange(getFacesContext(), component, change);
+        return change;
+      }
     }
     else
     {
-      aa = new AttributeComponentChange(attributeName, attributeValue);
+      return null;
     }
+  }
 
-    RequestContext adfContext = RequestContext.getCurrentInstance();
-    adfContext.getChangeManager().addComponentChange(context, this, aa);
+
+  /**
+   * Convenience function for
+   * <code>addComponentChange(new AttributeComponentChange(attributeName, attributeValue));</code>
+   * This function is not <code>final</code> for backwards compatibility reasons,
however,
+   * existing subclassers whould override <code>addComponentChange</code> instead.
+   * @param attributeName
+   * @param attributeValue
+   * @see #addComponentChange(UIComponent, ComponentChange)
+   */
+  protected void addAttributeChange(
+    String attributeName,
+    Object attributeValue)
+  {
+    addComponentChange(new AttributeComponentChange(attributeName, attributeValue));
   }
 
   void __rendererDecode(FacesContext context)
@@ -2482,6 +2556,8 @@ abstract public class UIXComponentBase e
     private Class<?> _componentClass;
   }
 
+  private static final String _NO_SUBTREE_CHANGE_ATTR = "_trinNoSubtreeChange";
+  
   private static final ClientIdCaching _CLIENT_ID_CACHING = _initClientIdCaching();
 
   // System property controlling whether client ID caching is enabled



Mime
View raw message