Author: gvanmatre
Date: Thu Oct 19 20:29:04 2006
New Revision: 465962

URL: http://svn.apache.org/viewvc?view=rev&rev=465962
Log:
The previous attempt at supporting something similar to the JSP 2.1 jspid's 
didn't work out (SHALE-67).  I overlooked all the reuse of the config beans.  
The same config bean might be pulled in to the same page composition several 
times thus creating duplicate component id's.  The config beans's jspid is now 
stored as a component's attribute and used to find its  location in a restored 
tree.  The view root is used to generate unique component ids.

Removed:
    
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/SequenceGenerator.java
Modified:
    
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java
    
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/Globals.java
    
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ComponentBean.java

Modified: 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java?view=diff&rev=465962&r1=465961&r2=465962
==============================================================================
--- 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java
 (original)
+++ 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java
 Thu Oct 19 20:29:04 2006
@@ -20,6 +20,7 @@
  */
 package org.apache.shale.clay.component.chain;
 
+import java.util.Iterator;
 import java.util.Map;
 
 import javax.faces.component.UIComponent;
@@ -34,7 +35,6 @@
 import org.apache.shale.clay.config.beans.AttributeBean;
 import org.apache.shale.clay.config.beans.Attributes;
 import org.apache.shale.clay.config.beans.ComponentBean;
-import org.apache.shale.clay.utils.JSFRuntimeTracker;
 
 /**
  * <p>
@@ -55,41 +55,6 @@
         log = LogFactory.getLog(CreateComponentCommand.class);
     }
 
-    /**
-     * <p>Tests to see if sun runtime 1.1.x is installed.</p>
-     *
-     * @return <code>true</code> if ri 1.1.x runtime is loaded
-     */
-    private boolean isRI11Installed() {
-       return (JSFRuntimeTracker.getJsfRuntime() == JSFRuntimeTracker.RI_1_1);
-    }
-
-
-    /**
-     * <p>Returns a unique component id for the request/response lifecycle.</p>
-     * @param configBean metadata bean used to build the JSF view
-     * @param facesContext faces context
-     * @return unique component id
-     */
-    private String createUniqueId(FacesContext facesContext, ComponentBean 
configBean) {
-        String id = null;
-
-        if (!isRI11Installed()) {
-            Map requestMap = facesContext.getExternalContext().getRequestMap();
-            SequenceGenerator generator = (SequenceGenerator) 
requestMap.get(Globals.CLAY_SEQUENCE_GENERATOR);
-            if (generator == null) {
-
-                generator = new SequenceGenerator();
-                requestMap.put(Globals.CLAY_SEQUENCE_GENERATOR, generator);
-            }
-            id = generator.createUniqueId(configBean);
-        } else {
-            id = facesContext.getViewRoot().createUniqueId();
-        }
-
-        return id;
-    }
-
 
     /**
      * <p>
@@ -139,12 +104,30 @@
         // evaluate nested symbols; symbols having symbols as values
         realizeSymbols(clayContext);
 
+        UIComponent child = null;
+        String facetName = displayElement.getFacetName();
+        if (facetName != null) {
+            facetName = replaceMnemonic(clayContext, facetName);
+        }
+        if (facetName != null) {
+            child = parent.getFacet(displayElement.getFacetName());
+        }
+        if (child == null) {
+           child = this.findComponentByJspId(parent, 
displayElement.getJspId());
+        }
+
+        String id = null;
+        if (child == null) {
+            id = displayElement.getId();
 
-        String id = displayElement.getId();
-        if (id == null) {
-            id = createUniqueId(facesContext, displayElement);
+            if (id == null) {
+                id = facesContext.getViewRoot().createUniqueId();
+                //id = createUniqueId(facesContext, displayElement);
+            } else {
+                id = replaceMnemonic(clayContext, id);
+            }
         } else {
-            id = replaceMnemonic(clayContext, id);
+            id = child.getId();
         }
 
         //Check to see if the replacement failed.  This can happen if the
@@ -161,18 +144,6 @@
                    new Object[] {id, symbolTable}));
         }
 
-        UIComponent child = null;
-        String facetName = displayElement.getFacetName();
-        if (facetName != null) {
-            facetName = replaceMnemonic(clayContext, facetName);
-        }
-
-        if (facetName != null) {
-            child = parent.getFacet(displayElement.getFacetName());
-        } else {
-            child = parent.findComponent(id);
-        }
-
         if (child == null) {
             try {
                 AttributeBean attr = displayElement.getAttribute("binding");
@@ -199,6 +170,7 @@
             }
 
             child.setId(id);
+            child.getAttributes().put(Globals.CLAY_JSPID_ATTRIBUTE, 
displayElement.getJspId());
             if (facetName != null) {
                 parent.getFacets().put(facetName, child);
 
@@ -255,5 +227,24 @@
         return isFinal;
     }
 
-
+    /**
+     * <p>Searches through the parent's children looking for a child
+     * component having a matching "org.apache.shale.clay.jspid" attribute.
+     * </p>
+     * @param parent owning <code>UIComponent</code>
+     * @param id target jsfid
+     * @return the child <code>UIComponent</code> if a match is found; 
otherwise;
+     *   a <code>null</code> value.
+     */
+    private UIComponent findComponentByJspId(UIComponent parent, String id) {
+        Iterator ci = parent.getChildren().iterator();
+        while (ci.hasNext()) {
+           UIComponent child = (UIComponent) ci.next();
+           String jspId = (String) 
child.getAttributes().get(Globals.CLAY_JSPID_ATTRIBUTE);
+           if (jspId != null && jspId.equals(id)) {
+              return child;
+           }
+        }
+        return null;
+    }
 }

Modified: 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/Globals.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/Globals.java?view=diff&rev=465962&r1=465961&r2=465962
==============================================================================
--- 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/Globals.java
 (original)
+++ 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/Globals.java
 Thu Oct 19 20:29:04 2006
@@ -272,5 +272,12 @@
      *
      */
     public static final String CLAY_CUSTOM_BUILDER_XMLNS = "XMLNS";
+
+    /**
+     * <p>The key value used to store clay's version of the <code>jspid</code>.
+     * This custom id is added to the <code>UIComponent</code>'s attributes
+     * map.</p>
+     */
+    public static final String CLAY_JSPID_ATTRIBUTE = 
"org.apache.shale.clay.jspid";
 }
 

Modified: 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ComponentBean.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ComponentBean.java?view=diff&rev=465962&r1=465961&r2=465962
==============================================================================
--- 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ComponentBean.java
 (original)
+++ 
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ComponentBean.java
 Thu Oct 19 20:29:04 2006
@@ -84,11 +84,11 @@
      *
      * @return unique id for a view element
      */
-    public long getJspId() {
+    public String getJspId() {
        if (jspId == -1) {
            jspId = generateId();
        }
-       return jspId;
+       return Long.toString(jspId);
     }
 
     /**


Reply via email to