myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r591935 - in /myfaces/trinidad/trunk/trinidad/trinidad-api/src/main: java/org/apache/myfaces/trinidad/change/ xrts/org/apache/myfaces/trinidad/resource/
Date Mon, 05 Nov 2007 09:39:40 GMT
Author: matzew
Date: Mon Nov  5 01:39:39 2007
New Revision: 591935

URL: http://svn.apache.org/viewvc?rev=591935&view=rev
Log:
TRINIDAD-792

applied fix to trunk, since it is generic and not specific to a particular JSF version.

Thanks to Shafi Khan for his patch!

Modified:
    myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/ChangeUtils.java
    myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/RemoveChildComponentChange.java
    myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/ReorderChildrenComponentChange.java
    myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts

Modified: myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/ChangeUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/ChangeUtils.java?rev=591935&r1=591934&r2=591935&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/ChangeUtils.java
(original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/ChangeUtils.java
Mon Nov  5 01:39:39 2007
@@ -42,10 +42,31 @@
    * Given a parent component and the identifier for the child, looks up among
    *  the children for a child with the specified identifier and returns.
    * Returns null if there were to be no such child
+   * @param parent the parent UIComponent
+   * @param childId the 'id' identifier value of child to be searched in the parent's 
+   *        children.
    */
   @SuppressWarnings("unchecked")
   public static UIComponent getChildForId(UIComponent parent, String childId)
   {
+    return getChildForId(parent, childId, "id");
+  }
+  
+  /**
+   * Given a parent component and the identifier value for the child, looks up among
+   * the children for a child with the specified identifier and returns.
+   * Returns null if there were to be no such child
+   * @param parent the parent UIComponent
+   * @param childId the identifier value of child to be searched in the parent's 
+   *        children.
+   * @param identifier the identifier type 
+   */
+  @SuppressWarnings("unchecked")
+  public static UIComponent getChildForId(
+    UIComponent parent, 
+    String childId,
+    String identifier)
+  {
     if (parent == null)
       return null;
 
@@ -53,12 +74,14 @@
     if (numChildren == 0)
       return null;
 
-    List children = parent.getChildren();
-    UIComponent child;
+    List<UIComponent> children = parent.getChildren();
+    
     for (int i=0; i<numChildren; i++)
     {
-      child = (UIComponent) children.get(i);
-      if ( childId.equals(child.getId()) )
+      UIComponent child = children.get(i);
+      Object attrVal = child.getAttributes().get(identifier);
+      
+      if ( childId.equals(attrVal) )
         return child;
     }
     return null;

Modified: myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/RemoveChildComponentChange.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/RemoveChildComponentChange.java?rev=591935&r1=591934&r2=591935&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/RemoveChildComponentChange.java
(original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/RemoveChildComponentChange.java
Mon Nov  5 01:39:39 2007
@@ -38,17 +38,37 @@
   /**
    * Constructs a RemoveChildChange with the specified identifier of the child.
    * @param childId The identifier of the child component that needs to be 
-   *         removed.
+   *        removed. If no identifier is specified, the type will be treated
+   *        as of 'id' type.
    * @throws IllegalArgumentException if specified childId were to be null.
    */
   public RemoveChildComponentChange(String childId)
   {
+    this(childId, "id");
+  }
+  
+  /**
+   * Constructs a RemoveChildChange with the specified identifier of the child.
+   * @param childId The identifier of the child component that needs to be 
+   *        removed.
+   * @param identifier Determines the type of identifier which is passed as the 
+   *        first argument. 
+   * @throws IllegalArgumentException if specified childId were to be null.
+   */
+  public RemoveChildComponentChange(String childId, String identifier)
+  {
     if ((childId == null) || (childId.length() == 0))
       throw new IllegalArgumentException(_LOG.getMessage(
         "CANNOT_CONSTRUCT_REMOVECHILDCHANGE_WITH_NULL_ID"));
+      
+    if (identifier == null || "".equals(identifier))
+      throw new IllegalArgumentException(_LOG.getMessage(
+      "IDENTIFIER_TYPE_CANNOT_BE_NULL"));
+    
     _childId = childId;
+    _identifier = identifier;
   }
-  
+    
   /**
    * Returns the identifier of child component that needs to be removed.
    */
@@ -58,6 +78,14 @@
   }
   
   /**
+   * Returns the identifier type.
+   */
+  public final String getIdentifier()
+  {
+    return _identifier;
+  }
+  
+  /**
    * {@inheritDoc}
    */
   @SuppressWarnings("unchecked")
@@ -68,7 +96,7 @@
       return;
       
     List<UIComponent> children = uiComponent.getChildren();
-    children.remove(ChangeUtils.getChildForId(uiComponent, _childId));
+    children.remove(ChangeUtils.getChildForId(uiComponent, _childId, _identifier));
   }
 
   /**
@@ -84,7 +112,7 @@
       
       if (attributes != null)
       {
-        Node idAttr = attributes.getNamedItem("id");
+        Node idAttr = attributes.getNamedItem(_identifier);
         
         if (idAttr != null)
         {
@@ -110,6 +138,7 @@
   }
 
   private final String _childId;
+  private final String _identifier;
   private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(
     RemoveChildComponentChange.class);
   private static final long serialVersionUID = 1L;

Modified: myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/ReorderChildrenComponentChange.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/ReorderChildrenComponentChange.java?rev=591935&r1=591934&r2=591935&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/ReorderChildrenComponentChange.java
(original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/ReorderChildrenComponentChange.java
Mon Nov  5 01:39:39 2007
@@ -43,18 +43,44 @@
    *         of child components.
    *        This List implementation should be of type java.io.Serializable in
    *         order to be persisted.
+   *        If no identifier was passed, it would be assumed that the list 
+   *          consists of the Ids. 
    * @throws IllegalArgumentException if supplied childIds were to be null.
    */
   public ReorderChildrenComponentChange(
     List<String> childIds
     )
   {
+    this(childIds, "id");
+  }
+  
+  /**
+   * Constructs a ReorderChange with the given List of identifiers for children.
+   * @param childIds An in-order collection (List) of Ids (as java.lang.String) 
+   *         of child components.
+   *        This List implementation should be of type java.io.Serializable in
+   *         order to be persisted.
+   * @param identifier Determines the type of identifiers which the List consists of.
+   * @throws IllegalArgumentException if supplied childIds were to be null or supplied 
+   *          identifier was to be null or emtpy string.
+   */
+  public ReorderChildrenComponentChange(
+    List<String> childIds,
+    String identifier
+    )
+  {
     if (childIds == null)
       throw new IllegalArgumentException(_LOG.getMessage(
         "CANNOT_CONSTRUCT_REORDERCHANGE_WITH_NULL_ID"));
-  
+    
+    if (identifier == null || "".equals(identifier))
+      throw new IllegalArgumentException(_LOG.getMessage(
+        "IDENTIFIER_TYPE_CANNOT_BE_NULL"));
+    
     // make serializable copy of list        
     _childIds = Collections.unmodifiableList(new ArrayList<String>(childIds));
+    
+    _identifier = identifier;
   }
   
   /**
@@ -66,6 +92,14 @@
   }
   
   /**
+   * Returns the identifier type.
+   */
+  public final String getIdentifier()
+  {
+    return _identifier;
+  }
+  
+  /**
    * {@inheritDoc}
    * In case children were to be removed between the time when this Change was
    *  added, and the time when it was applied, maybe due to application of a
@@ -88,9 +122,19 @@
     Map<String, UIComponent> childrenMap = new LinkedHashMap<String, UIComponent>();
     
     List<UIComponent> children = uiComponent.getChildren();
+    
+    int fakeIndex = 0;
     for(UIComponent child : children)
     {
-      childrenMap.put(child.getId(), child);
+      String attrValue = (String)child.getAttributes().get(_identifier);
+      
+      // create a dummy key to maintain order of children whose identifier 
+      // does not exist
+      if (attrValue == null) 
+      {
+        attrValue = Integer.valueOf(fakeIndex++).toString();
+      }
+      childrenMap.put(attrValue, child);
     }
 
     // remove the children so that we can add them back in
@@ -133,15 +177,15 @@
         
     Node currChild = componentNode.getFirstChild();
     
+    int fakeIndex = 0;
     while (currChild != null)
     {
-      int fakeIndex = 0;
       NamedNodeMap attributes = currChild.getAttributes();
-      
+              
       String currKey = null;
       if (attributes != null)
       {
-        Node idAttr = attributes.getNamedItem("id");
+        Node idAttr = attributes.getNamedItem(_identifier);
         
         if (idAttr != null)
         {
@@ -195,6 +239,7 @@
   }
 
   private final List<String> _childIds;
+  private final String _identifier;
   private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(
     ReorderChildrenComponentChange.class);
   private static final long serialVersionUID = 1L;

Modified: myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts?rev=591935&r1=591934&r2=591935&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts
(original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts
Mon Nov  5 01:39:39 2007
@@ -216,6 +216,9 @@
  <!-- CANNOT_CONSTRUCT_REORDERCHANGE_WITH_NULL_ID -->
  <resource key="CANNOT_CONSTRUCT_REORDERCHANGE_WITH_NULL_ID">Cannot construct a ReorderChange
with null child ids.</resource>
  
+ <!-- IDENTIFIER_TYPE_CANNOT_BE_NULL -->
+ <resource key="IDENTIFIER_TYPE_CANNOT_BE_NULL">Identifier type cannot be null or empty
string.</resource>
+
  <!-- CANNOT_CONSTRUCT_ADDFACETCHANGE_WITH_NULL_FACETNAME_FACETCOMPONENT -->
  <resource key="CANNOT_CONSTRUCT_ADDFACETCHANGE_WITH_NULL_FACETNAME_FACETCOMPONENT">Cannot
construct an AddFacetChange with either of facetName or facetComponent being null.</resource>
  



Mime
View raw message