myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bsulli...@apache.org
Subject svn commit: r918848 - in /myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src: main/java/org/apache/myfaces/trinidad/component/ test/java/org/apache/myfaces/trinidad/render/
Date Thu, 04 Mar 2010 04:28:45 GMT
Author: bsullivan
Date: Thu Mar  4 04:28:45 2010
New Revision: 918848

URL: http://svn.apache.org/viewvc?rev=918848&view=rev
Log:
Fixes for TRINIDAD-1740 Replace Trinidad TreeVisiting APIs with JSF 2 TreeVisiting APIs
TRINIDAD-1669 Improve transient memory consumption of UIXComponentBase.getClientId()

UIXComponent was accidentally calling the wrong CoreRenderer versions of setup/tearDownEncoding
context (the deprecated ones that take UIXComponents, rather than the correct ones that take
UIComponents)

Fix UIXComponentBase clientID caching enabling code
Speed up clientId clearing when stamping in UIXCollection

Modified:
    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
    myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/test/java/org/apache/myfaces/trinidad/render/RenderUtilsTest.java

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=918848&r1=918847&r2=918848&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
Thu Mar  4 04:28:45 2010
@@ -812,7 +812,10 @@
     // ensure the client IDs are reset on the component, otherwise they will not get the
     // proper stamped IDs. This mirrors the behavior in UIData and follows the JSF specification
     // on when client IDs are allowed to be cached and when they must be reset
-    clearCachedClientIds();
+    List<UIComponent> stamps = getStamps();
+    
+    for (UIComponent stamp : stamps)
+      UIXComponent.clearCachedClientIds(stamp);
   }
 
   /**

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=918848&r1=918847&r2=918848&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
Thu Mar  4 04:28:45 2010
@@ -797,7 +797,7 @@
     {
       CoreRenderer coreRenderer = (CoreRenderer)renderer;
 
-      coreRenderer.setupEncodingContext(context, rc, this);
+      coreRenderer.setupEncodingContext(context, rc, (UIComponent)this);
     }
   }
 
@@ -851,7 +851,7 @@
       {
         CoreRenderer coreRenderer = (CoreRenderer)renderer;
 
-        coreRenderer.tearDownEncodingContext(context, rc, this);
+        coreRenderer.tearDownEncodingContext(context, rc, (UIComponent)this);
       }
     }
     finally

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=918848&r1=918847&r2=918848&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
Thu Mar  4 04:28:45 2010
@@ -31,6 +31,8 @@
 import java.util.Map;
 import java.util.Properties;
 
+import java.util.concurrent.atomic.AtomicReference;
+
 import javax.el.ELContext;
 import javax.el.ELException;
 import javax.el.MethodExpression;
@@ -346,28 +348,39 @@
     return clientId;
   }
 
-
   @Override
   public String getClientId(FacesContext context)
   {
-    return _calculateClientId(context);
-/* TODO put back in when we fix all of the clientID caching issues
-    String clientId = _clientId;
-    
-    if (clientId == null)
+    if (_isClientIdCachingEnabled(context))
     {
-      clientId = _calculateClientId(context);
+      String clientId = _clientId;
       
-      if (_usesFacesBeanImpl)
-        _clientId = clientId;
+      if (clientId == null)
+      {
+        clientId = _calculateClientId(context);
+        
+        if (_usesFacesBeanImpl)
+        {
+          _clientId = clientId;
+        }
+      }
+      else
+      {
+        // for now validate success by checking the cached result against the dynamically
+        // generated result
+        String realID = _calculateClientId(context);
+        
+        if (!clientId.equals(realID))
+          throw new IllegalStateException(
+        "cached client id " + clientId + " for " + this + " doesn't match client id:" + realID);
+      }
+    
+      return clientId;
     }
     else
     {
-      assert clientId.equals(_calculateClientId(context)) :
-      "cached client id " + _clientId + " for " + this + " doesn't match client id:" + _calculateClientId(context);
+      return _calculateClientId(context);
     }
-    return clientId;
-*/
   }
 
   /**
@@ -421,8 +434,6 @@
   @Override
   public void setId(String id)
   {
-    _clientId = null;
-
     FacesBean facesBean = getFacesBean();
 
     // if we are using a FacesBeanImpl, then the FacesBean will
@@ -450,6 +461,8 @@
       _validateId(id);
       facesBean.setProperty(ID_KEY, id);      
     }
+
+    _clientId = null;
   }
 
   @Override
@@ -464,7 +477,7 @@
   /**
    * <p>Set the parent <code>UIComponent</code> of this
    * <code>UIComponent</code>.</p>
-   * 
+   *
    * @param parent The new parent, or <code>null</code> for the root node
    *  of a component tree
    */
@@ -472,33 +485,51 @@
   public void setParent(UIComponent parent)
   {
     // do we add this component ?
-    if (parent != null)
+    if (parent != _parent)
     {
-      // set the reference
-      _parent = parent;
-
-      if (parent.isInView())
+      if (parent != null)
       {
-        // trigger the ADD_EVENT and call setInView(true)
-        // recursive for all kids/facets...
-        // Application.publishEvent(java.lang.Class, java.lang.Object)  must be called, passing

-        // PostAddToViewEvent.class as the first argument and the newly added component as
the second 
-        // argument.
-        _publishPostAddToViewEvent(getFacesContext(), this);
+        // set the reference
+        _parent = parent;
+
+        if (parent.isInView())
+        {
+          // trigger the ADD_EVENT and call setInView(true)
+          // recursive for all kids/facets...
+          // Application.publishEvent(java.lang.Class, java.lang.Object)  must be called,
passing 
+          // PostAddToViewEvent.class as the first argument and the newly added component
as the second 
+          // argument.
+          _publishPostAddToViewEvent(getFacesContext(), this);
+        }
       }
-    }
-    else
-    {
-      if (_parent != null && _parent.isInView())
+      else
       {
-        // trigger the "remove event" lifecycle
-        // and call setInView(false) for all children/facets
-        // doing this => recursive
-        _publishPreRemoveFromViewEvent(getFacesContext(), this);
+        if (_parent != null && _parent.isInView())
+        {
+          // trigger the "remove event" lifecycle
+          // and call setInView(false) for all children/facets
+          // doing this => recursive
+          _publishPreRemoveFromViewEvent(getFacesContext(), this);
+        }
+
+        // (un)set the reference
+        _parent = parent;
       }
 
-      // (un)set the reference
-      _parent = parent;
+      // clear cached client ids if necessary
+      if (_clientId != null)
+      {
+        String newClientId = _calculateClientId(FacesContext.getCurrentInstance());
+        
+        // if our clientId changed as a result of being reparented (because we moved
+        // between NamingContainers for instance) then we need to clear out
+        // all of the cached client ids for our subtree
+        if (!_clientId.equals(newClientId))
+        {
+          clearCachedClientIds();
+          _clientId = newClientId;
+        }
+      }
     }
   }
 
@@ -772,7 +803,6 @@
     return true;
   }
 
-
   // ------------------------------------------- Lifecycle Processing Methods
 
   @Override
@@ -1922,7 +1952,6 @@
   private Map<String, Object>      _attributes;
   private Map<String, UIComponent> _facets;
   private UIComponent              _parent;
-
   private String                   _id;
   private String                   _clientId;
   private boolean                  _usesFacesBeanImpl;
@@ -1993,6 +2022,44 @@
   {
   }
 
+  /**
+   * Temporary function controlling whether clientId caching is enabled
+   */
+  private static boolean _isClientIdCachingEnabled(FacesContext context)
+  {
+    if (context == null)
+      throw new IllegalArgumentException("FacesContext is null");
+
+    Boolean cacheClientIds = _sClientIdCachingEnabled.get();
+    
+    if (cacheClientIds == null)
+    {
+      // get the servlet initialization parameter
+      String cachingParam = context.getExternalContext().getInitParameter(
+                                                             _INIT_PROP_CLIENT_ID_CACHING_ENABLED);
+      
+      Boolean cachingEnabled  = (cachingParam != null)
+                                  ? Boolean.valueOf(cachingParam)
+                                  : Boolean.FALSE;  // default to false
+
+      // cache the servlet initialization value
+      _sClientIdCachingEnabled.set(cachingEnabled ? Boolean.TRUE : Boolean.FALSE);
+
+      return cachingEnabled;
+    }
+    else
+    {
+      return cacheClientIds.booleanValue();
+    }
+  }
+  
+  private static AtomicReference<Boolean> _sClientIdCachingEnabled = 
+                                                                 new AtomicReference<Boolean>(null);
+  
+  // temporary servlet initialization flag controlling whether client ID caching is enabled
+  private static final String _INIT_PROP_CLIENT_ID_CACHING_ENABLED = 
+                                      "org.apache.myfaces.trinidadinternal.ENABLE_CLIENT_ID_CACHING";
+
   static private final LifecycleRenderer _UNDEFINED_LIFECYCLE_RENDERER =
                                                 new ExtendedRendererImpl();
   static private final Renderer _UNDEFINED_RENDERER = new RendererImpl();

Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/test/java/org/apache/myfaces/trinidad/render/RenderUtilsTest.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/test/java/org/apache/myfaces/trinidad/render/RenderUtilsTest.java?rev=918848&r1=918847&r2=918848&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/test/java/org/apache/myfaces/trinidad/render/RenderUtilsTest.java
(original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-api/src/test/java/org/apache/myfaces/trinidad/render/RenderUtilsTest.java
Thu Mar  4 04:28:45 2010
@@ -31,8 +31,9 @@
 import org.apache.myfaces.trinidad.component.UIXInput;
 import org.apache.myfaces.trinidad.component.UIXPanel;
 
+import org.apache.myfaces.trinidadbuild.test.FacesTestCase;
 
-public class RenderUtilsTest extends TestCase
+public class RenderUtilsTest extends FacesTestCase
 {
   public static final Test suite()
   {
@@ -89,6 +90,8 @@
   @SuppressWarnings("unchecked")
   public void testButtonAndNamingContainerSiblings()
   {
+    FacesContext context = FacesContext.getCurrentInstance();
+
       // rootPanel
       //     button1
       //     table1
@@ -105,41 +108,41 @@
       table1.getChildren().add(tableChild);
     
     String relativeId =
-      RenderUtils.getRelativeId(null, button1, "table1");
+      RenderUtils.getRelativeId(context, button1, "table1");
     assertEquals("table1", relativeId);
     
     relativeId =
-      RenderUtils.getRelativeId(null, button1, ":table1");
+      RenderUtils.getRelativeId(context, button1, ":table1");
     assertEquals("table1", relativeId);
     
     // new way would find nothing, so we'd have to get something logical
     relativeId =
-      RenderUtils.getRelativeId(null, table1, "someRandomId");
+      RenderUtils.getRelativeId(context, table1, "someRandomId");
     assertEquals("table1_Client:someRandomId", relativeId);
     
     relativeId =
-      RenderUtils.getRelativeId(null, table1, ":commandButton1");
+      RenderUtils.getRelativeId(context, table1, ":commandButton1");
     assertEquals("commandButton1", relativeId);
 
     // to get to the commandButton from the table, you need to pop out of the
     // table
     relativeId =
-      RenderUtils.getRelativeId(null, table1, "::commandButton1");
+      RenderUtils.getRelativeId(context, table1, "::commandButton1");
     assertEquals("commandButton1", relativeId);
     
     // backward compatibility test -- this was the old syntax for siblings to the table.
     // this should be found by looking at the nc's parent from findRelativeComponent
     relativeId =
-      RenderUtils.getRelativeId(null, table1, "commandButton1");
+      RenderUtils.getRelativeId(context, table1, "commandButton1");
     assertEquals("commandButton1", relativeId);
        
     // backward compatibility test -- this was the old syntax for children to the table.
     relativeId =
-      RenderUtils.getRelativeId(null, table1, "table1:tableChildId");
+      RenderUtils.getRelativeId(context, table1, "table1:tableChildId");
     assertEquals("table1:tableChildId", relativeId);
      // this is the new syntax for children to the table
     relativeId =
-      RenderUtils.getRelativeId(null, table1, "tableChildId");
+      RenderUtils.getRelativeId(context, table1, "tableChildId");
     assertEquals("table1:tableChildId", relativeId);
 
   }
@@ -150,6 +153,7 @@
   @SuppressWarnings("unchecked")
   public void testRelativeSearch()
   {
+    FacesContext context = FacesContext.getCurrentInstance();
 
 
       // set up component hierarchy
@@ -195,13 +199,13 @@
      */
       
     String relativeId =
-      RenderUtils.getRelativeId(null, input1, "::button1");
+      RenderUtils.getRelativeId(context, input1, "::button1");
     // new way should pop OUT of ONE naming container and will find it
     assertEquals("ncRoot:button1", relativeId);
 
     
     relativeId =
-      RenderUtils.getRelativeId(null, input1, ":::button1");
+      RenderUtils.getRelativeId(context, input1, ":::button1");
     // new way should pop OUT of TWO naming containers and will find not find it
     // since it is in ncRoot and the base is now the view root.
     // so it goes to the old findRelativeComponent, and this will find it.
@@ -209,27 +213,27 @@
 
 
     relativeId =
-      RenderUtils.getRelativeId(null, input1, "randomPeer");
+      RenderUtils.getRelativeId(context, input1, "randomPeer");
     // randomPeer doesn't exist, so new way won't find it.
     // uses code that doesn't need to find the component to return this:
     assertEquals("nc1_Client:randomPeer", relativeId);
     
     relativeId =
-      RenderUtils.getRelativeId(null, input1, "::randomPeer");
+      RenderUtils.getRelativeId(context, input1, "::randomPeer");
     // randomPeer doesn't exist, so new way won't find it.
     // uses code that doesn't need to find the component to return this:
     assertEquals("ncRoot_Client:randomPeer", relativeId);
  
     // rootButton is child of form and sibling to ncRoot. It's 2 nc up from input1
     relativeId =
-      RenderUtils.getRelativeId(null, input1, ":::rootButton");
+      RenderUtils.getRelativeId(context, input1, ":::rootButton");
     // new way should pop OUT of both NC with ::: and will find it
     assertEquals("rootButton", relativeId);
 
  
     // rootButton is child of form and sibling to ncRoot. It's 2 nc up from input1
     relativeId =
-      RenderUtils.getRelativeId(null, input1, "::rootButton");
+      RenderUtils.getRelativeId(context, input1, "::rootButton");
     // new way should pop OUT of one NC with ::, so it can't find it
     // the 'old' findRelativeComponent can't find it either.
     // so it returns what the old getRelativeId would have returned
@@ -240,19 +244,19 @@
     
     // rootButton is child of form and sibling to ncRoot. It's 2 nc up from input1
     relativeId =
-      RenderUtils.getRelativeId(null, input1, "::::rootButton");
+      RenderUtils.getRelativeId(context, input1, "::::rootButton");
     // new way should pop OUT of ALL NCs and will find it.
     assertEquals("rootButton", relativeId);
     
 
     
     relativeId =
-      RenderUtils.getRelativeId(null, input1, "::::button1");
+      RenderUtils.getRelativeId(context, input1, "::::button1");
     // new way should return this
     assertEquals("button1", relativeId);
     
     relativeId =
-      RenderUtils.getRelativeId(null, input1, ":::::button1");
+      RenderUtils.getRelativeId(context, input1, ":::::button1");
     assertEquals("button1", relativeId);
   }
 



Mime
View raw message