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 2011/11/04 22:05:55 UTC

svn commit: r1197774 - in /myfaces/trinidad/branches/ar_1940: trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tagDemos/ trinidad-examples/trinidad-demo/src/mai...

Author: arobinson74
Date: Fri Nov  4 21:05:54 2011
New Revision: 1197774

URL: http://svn.apache.org/viewvc?rev=1197774&view=rev
Log:
Indexing working for the components but the varStatus logic is flawed still

Modified:
    myfaces/trinidad/branches/ar_1940/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TagComponentBridge.java
    myfaces/trinidad/branches/ar_1940/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UIXComponentELTag.java
    myfaces/trinidad/branches/ar_1940/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tagDemos/ForEachBean.java
    myfaces/trinidad/branches/ar_1940/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/forEach.jspx
    myfaces/trinidad/branches/ar_1940/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/ForEachTag.java

Modified: myfaces/trinidad/branches/ar_1940/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TagComponentBridge.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/ar_1940/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TagComponentBridge.java?rev=1197774&r1=1197773&r2=1197774&view=diff
==============================================================================
--- myfaces/trinidad/branches/ar_1940/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TagComponentBridge.java (original)
+++ myfaces/trinidad/branches/ar_1940/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TagComponentBridge.java Fri Nov  4 21:05:54 2011
@@ -23,11 +23,20 @@ import javax.faces.component.UIComponent
 
 import javax.servlet.jsp.PageContext;
 
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+
 
 /**
- * Internal class to handle communication between iterating tags
- * ({@link TrinidadIterationTag}) and component tags
- * ({@link UIXComponentELTag}).
+ * Internal class to handle communication between iterating tags ({@link TrinidadIterationTag})
+ * and component tags ({@link UIXComponentELTag}).
+ * <p>This class is notified by
+ * {@link UIXComponentELTag#findComponent(javax.faces.context.FacesContext)} to allow iteration
+ * in the tag ancestry to be notified during subsequent requests that the component was
+ * processed.It is also notified by {@link UIXComponentELTag#doEndTag()} to allow ancestor
+ * iteration tags to be notified that a component has finished being processed.</p>
+ * <p>The reason for this is that it allows for the iteration tags, specifically the
+ * ForEachTag, to know when a child tag has been processed so that it can map the component to
+ * the iteration.</p>
  */
 final class TagComponentBridge
 {
@@ -46,14 +55,12 @@ final class TagComponentBridge
   final static TagComponentBridge getInstance(PageContext pageContext)
   {
     TagComponentBridge bridge =
-      (TagComponentBridge) pageContext.getAttribute(_PAGE_CONTEXT_KEY,
-        PageContext.REQUEST_SCOPE);
+      (TagComponentBridge)pageContext.getAttribute(_PAGE_CONTEXT_KEY, PageContext.REQUEST_SCOPE);
 
     if (bridge == null)
     {
       bridge = new TagComponentBridge();
-      pageContext.setAttribute(_PAGE_CONTEXT_KEY, bridge,
-          PageContext.REQUEST_SCOPE);
+      pageContext.setAttribute(_PAGE_CONTEXT_KEY, bridge, PageContext.REQUEST_SCOPE);
     }
 
     return bridge;
@@ -68,7 +75,10 @@ final class TagComponentBridge
   void notifyComponentProcessed(
     UIComponent component)
   {
-    System.out.println("Component processed: " + component.getClientId());
+    if (_LOG.isFine())
+    {
+      _LOG.fine("Component processed: {0}", component.getClientId());
+    }
     for (TrinidadIterationTag tag : _tags)
     {
       tag.childComponentProcessed(component);
@@ -84,7 +94,11 @@ final class TagComponentBridge
   void notifyAfterComponentProcessed(
     UIComponent component)
   {
-    System.out.println("After component processed: " + component.getClientId());
+    if (_LOG.isFine())
+    {
+      _LOG.fine("After component processed: {0}", component.getClientId());
+    }
+
     for (TrinidadIterationTag tag : _tags)
     {
       tag.afterChildComponentProcessed(component);
@@ -114,4 +128,6 @@ final class TagComponentBridge
 
   private final static String _PAGE_CONTEXT_KEY =
     TagComponentBridge.class.getName() + ".PAGE_CONTEXT";
+  private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(
+    TagComponentBridge.class);
 }
\ No newline at end of file

Modified: myfaces/trinidad/branches/ar_1940/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UIXComponentELTag.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/ar_1940/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UIXComponentELTag.java?rev=1197774&r1=1197773&r2=1197774&view=diff
==============================================================================
--- myfaces/trinidad/branches/ar_1940/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UIXComponentELTag.java (original)
+++ myfaces/trinidad/branches/ar_1940/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UIXComponentELTag.java Fri Nov  4 21:05:54 2011
@@ -37,7 +37,6 @@ import javax.el.ValueExpression;
 import javax.faces.component.NamingContainer;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIViewRoot;
-import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.faces.webapp.UIComponentELTag;
 
@@ -101,12 +100,6 @@ abstract public class UIXComponentELTag 
     //  created. End of document tag is a best bet.
     if (component instanceof UIXDocument)
     {
-      if (getCreated())
-      {
-        ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
-        // Used by SessionChangeManager to confirm that the state was not restored.
-        ec.getRequestMap().put(_DOCUMENT_CREATED_KEY, Boolean.TRUE);
-      }
       ChangeManager cm = RequestContext.getCurrentInstance().getChangeManager();
       cm.applyComponentChangesForCurrentView(FacesContext.getCurrentInstance());
     }
@@ -123,8 +116,9 @@ abstract public class UIXComponentELTag 
     setId(_origId);
     _origId = null;
 
-    TagComponentBridge bridge = TagComponentBridge
-      .getInstance(pageContext);
+    // Make iteration tags aware that the processing of this component is now complete so that
+    // the tags are able to determine heirarchies.
+    TagComponentBridge bridge = TagComponentBridge.getInstance(pageContext);
     bridge.notifyAfterComponentProcessed(getComponentInstance());
 
     return super.doEndTag();
@@ -134,13 +128,15 @@ abstract public class UIXComponentELTag 
   protected UIComponent findComponent(FacesContext context)
     throws JspException
   {
+    // Note that although this method is called "findComponent", it is actually a find or create
+    // component. When the super class method is called, it will first look for the component, and
+    // if it is not found, it will create one. Therefore, after this super call returns, the
+    // component will be non-null
     UIComponent component = super.findComponent(context);
 
-    // Notify any listening tags that this component was found or
-    // created (this method actually does create the compnoent if it
-    // was not found, so it is a bit mis-named in JSF)
-    TagComponentBridge bridge = TagComponentBridge
-      .getInstance(pageContext);
+    // Notify any listening tags that this component was found or created. This allows iteration
+    // tags to know what components belong to each iteration.
+    TagComponentBridge bridge = TagComponentBridge.getInstance(pageContext);
     bridge.notifyComponentProcessed(component);
 
     return component;
@@ -211,7 +207,7 @@ abstract public class UIXComponentELTag 
   }
 
   /**
-   * Set a property of type java.util.List<java.lang.String>.  If the value
+   * Set a property of type java.util.List&lt;java.lang.String>.  If the value
    * is an EL expression, it will be stored as a ValueExpression.
    * Otherwise, it will parsed as a whitespace-separated series
    * of strings.
@@ -237,7 +233,7 @@ abstract public class UIXComponentELTag 
   }
 
   /**
-   * Set a property of type java.util.Set<java.lang.String>.  If the value
+   * Set a property of type java.util.Set&lt;java.lang.String>.  If the value
    * is an EL expression, it will be stored as a ValueExpression.
    * Otherwise, it will parsed as a whitespace-separated series
    * of strings.
@@ -585,7 +581,10 @@ abstract public class UIXComponentELTag 
     return sdf;
   }
 
-  private static final String _DOCUMENT_CREATED_KEY = "org.apache.myfaces.trinidad.DOCUMENTCREATED";
+  /** @deprecated Not used any more in the session state manager */
+  @Deprecated
+  public static final String DOCUMENT_CREATED_KEY = "org.apache.myfaces.trinidad.DOCUMENTCREATED";
+
   private final static String _UNIQUE_ID_KEY = UIXComponentELTag.class.getName() + ".ID";
 
   private MethodExpression  _attributeChangeListener;

Modified: myfaces/trinidad/branches/ar_1940/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tagDemos/ForEachBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/ar_1940/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tagDemos/ForEachBean.java?rev=1197774&r1=1197773&r2=1197774&view=diff
==============================================================================
--- myfaces/trinidad/branches/ar_1940/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tagDemos/ForEachBean.java (original)
+++ myfaces/trinidad/branches/ar_1940/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tagDemos/ForEachBean.java Fri Nov  4 21:05:54 2011
@@ -19,6 +19,7 @@ import org.apache.myfaces.trinidad.chang
 import org.apache.myfaces.trinidad.component.UIXCommand;
 import org.apache.myfaces.trinidad.component.visit.VisitTreeUtils;
 import org.apache.myfaces.trinidad.context.RequestContext;
+import org.apache.myfaces.trinidad.model.RowKeyPropertyModel;
 import org.apache.myfaces.trinidad.model.SortCriterion;
 import org.apache.myfaces.trinidad.model.SortableModel;
 
@@ -67,12 +68,13 @@ public class ForEachBean
   {
     _simpleList = Arrays.asList(
                     "One", "Two", "Three", "Four");
-    _model = new SortableModel(
+    _model = new RowKeyPropertyModel(
                Arrays.asList(
                  new Person("a", "John", "Doe"),
                  new Person("b", "Jane", "Doe"),
                  new Person("c", "Bob", "Smith"),
-                 new Person("d", "Alice", "Jones")));
+                 new Person("d", "Alice", "Jones")),
+               "key");
   }
 
   public final void setSortProperty(String sortProperty)
@@ -200,7 +202,7 @@ public class ForEachBean
   }
 
   private final List<String> _simpleList;
-  private final SortableModel _model;
+  private final RowKeyPropertyModel _model;
   private String _sortProperty;
   private boolean _sortAscending;
 }

Modified: myfaces/trinidad/branches/ar_1940/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/forEach.jspx
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/ar_1940/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/forEach.jspx?rev=1197774&r1=1197773&r2=1197774&view=diff
==============================================================================
--- myfaces/trinidad/branches/ar_1940/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/forEach.jspx (original)
+++ myfaces/trinidad/branches/ar_1940/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/forEach.jspx Fri Nov  4 21:05:54 2011
@@ -93,7 +93,8 @@
                                      value="First name: #{person.firstName}"/>
                       <tr:outputText id="lastName"
                                      value="Last name: #{person.lastName}"/>
-                      <tr:outputText value="(Panel group layout client ID: #{component.parent.clientId})"/>
+                      <tr:outputText id="clientId"
+                                     value="(Panel group layout client ID: #{component.parent.clientId})"/>
                     </tr:panelGroupLayout>
                     <tr:separator id="sep1" rendered="#{not vs.last}" />
                   </tr:forEach>

Modified: myfaces/trinidad/branches/ar_1940/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/ForEachTag.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/ar_1940/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/ForEachTag.java?rev=1197774&r1=1197773&r2=1197774&view=diff
==============================================================================
--- myfaces/trinidad/branches/ar_1940/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/ForEachTag.java (original)
+++ myfaces/trinidad/branches/ar_1940/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/ForEachTag.java Fri Nov  4 21:05:54 2011
@@ -74,7 +74,6 @@ public class ForEachTag
 {
   public ForEachTag()
   {
-    System.out.println("ForEachTag created");
   }
 
   public void setItems(ValueExpression items)
@@ -113,7 +112,7 @@ public class ForEachTag
   @Override
   public void setJspId(String id)
   {
-    System.out.println("setJspId: " + id);
+    _LOG.finest("setJspId called with ID {0}", id);
     // If the view attributes are null, then this is the first time this method has been called
     // for this request.
     if (_viewAttributes == null)
@@ -148,7 +147,7 @@ public class ForEachTag
   protected int doStartTagImpl()
     throws JspException
   {
-    System.out.println("doStartTagImpl");
+    _LOG.finest("doStartTagImpl called on tag with ID {0}", getId());
     _validateAttributes();
 
     FacesContext facesContext = FacesContext.getCurrentInstance();
@@ -224,8 +223,7 @@ public class ForEachTag
     _isLast = _currentIndex == _currentEnd;
 
     // Save off the previous deferred variables
-    VariableMapper vm =
-      pageContext.getELContext().getVariableMapper();
+    VariableMapper vm = pageContext.getELContext().getVariableMapper();
 
     if (_var != null)
     {
@@ -249,7 +247,7 @@ public class ForEachTag
   @Override
   public int doAfterBody()
   {
-    System.out.println("doAfterBody");
+    _LOG.finest("doAfterBody processing on tag {0}", getId());
     _currentIndex += _currentStep;
     ++_currentCount;
     _isFirst = false;
@@ -259,8 +257,7 @@ public class ForEachTag
     if (_currentEnd < _currentIndex)
     {
       // Restore EL state
-      VariableMapper vm =
-        pageContext.getELContext().getVariableMapper();
+      VariableMapper vm = pageContext.getELContext().getVariableMapper();
       if (_var != null)
         vm.setVariable(_var, _previousDeferredVar);
       if (_varStatus != null)
@@ -297,7 +294,7 @@ public class ForEachTag
     _previousDeferredVar = null;
     _previousDeferredVarStatus = null;
 
-    System.out.println("release called");
+    _LOG.finest("release called");
     _iterationId = null;
     _iterationData = null;
     _viewAttributes = null;
@@ -320,8 +317,12 @@ public class ForEachTag
     {
       Map<String, Object> compAttrs = component.getAttributes();
       Integer iterationId = (Integer)compAttrs.get(_ITERATION_ID_KEY);
-      System.out.println("childComponentProcessed: " + component +
-                         " Previous component iteration ID: " + iterationId);
+      if (_LOG.isFinest())
+      {
+        _LOG.finest(
+          "childComponentProcessed: {0} ({1}). Previous component iteration ID: {2}",
+          new Object[] { component.getClass().getName(), component.getClientId(), iterationId });
+      }
 
       if (iterationId == null)
       {
@@ -348,7 +349,11 @@ public class ForEachTag
     // We are only interested in components that are directly under our parent.
     if (component.getParent() == _parentComponent)
     {
-      System.out.println("afterChildComponentProcessed: " + component);
+      if (_LOG.isFinest())
+      {
+        _LOG.finest("afterChildComponentProcessed on component {0} ({1})",
+          new Object[] { component.getClass().getName(), component.getClientId() });
+      }
       // Store a unique iteration ID in each component. That way, if a component is ever moved
       // from one iteration to another between requests, but not all the components, no problems
       // will ensue. The use case is that ${} is used in the ID of one or more child components
@@ -373,16 +378,14 @@ public class ForEachTag
   private void _updateVars(
     boolean createNewIterationData)
   {
-    VariableMapper vm =
-      pageContext.getELContext().getVariableMapper();
+    VariableMapper vm = pageContext.getELContext().getVariableMapper();
 
     // Generate a new iteration ID
     _updateIterationId();
 
     if (_var != null)
     {
-      // Catch programmer error where _var has been set but
-      // _items has not
+      // Catch programmer error where _var has been set but _items has not
       if (_items != null)
       {
         // Determine if we need to use a key or an index based value expression
@@ -436,7 +439,13 @@ public class ForEachTag
     {
       _previousDeferredVarStatus = vm.resolveVariable(_varStatus);
 
-
+      if (_LOG.isFinest())
+      {
+        _LOG.finest("Storing iteration map key for varStatus." +
+          "\nIteration ID: {0}" +
+          "\nMap key     : {1}",
+          new Object[] { _iterationId, _iterationMapKey });
+      }
       // Store a new var status value expression into the variable mapper
       vm.setVariable(_varStatus, new VarStatusValueExpression(_iterationId, _iterationMapKey));
     }
@@ -521,7 +530,7 @@ public class ForEachTag
       _iterationId = intObj + 1;
     }
 
-    System.out.println("Iteration ID is now " + _iterationId);
+    _LOG.finest("Iteration ID is now {0}", _iterationId);
     _viewAttributes.put(_ITERATION_ID_KEY, _iterationId);
 
     if (_iterationData != null)
@@ -1044,14 +1053,13 @@ public class ForEachTag
       int          index,
       int          end)
     {
-      super();
-      this._key = key;
-      this._first = first;
-      this._last = last;
-      this._begin = begin;
-      this._count = count;
-      this._index = index;
-      this._end = end;
+      _key = key;
+      _first = first;
+      _last = last;
+      _begin = begin;
+      _count = count;
+      _index = index;
+      _end = end;
     }
 
     public final boolean isLast()
@@ -1089,6 +1097,9 @@ public class ForEachTag
       return _key;
     }
 
+    @SuppressWarnings("compatibility:-1418334454154750553")
+    private static final long serialVersionUID = 1L;
+
     private boolean _last;
     private boolean _first;
     private int _begin;
@@ -1096,8 +1107,6 @@ public class ForEachTag
     private int _index;
     private int _end;
     private Serializable _key;
-
-    private static final long serialVersionUID = 0L;
   }
 
   private int _currentBegin;