You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2009/12/01 22:43:00 UTC

svn commit: r885951 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces: renderkit/html/ view/facelets/compiler/ view/facelets/impl/ view/facelets/tag/composite/ view/facelets/tag/jsf/

Author: lu4242
Date: Tue Dec  1 21:42:59 2009
New Revision: 885951

URL: http://svn.apache.org/viewvc?rev=885951&view=rev
Log:
MYFACES-2428 Id generation for facelets cause problems with htmlunit 2.4 or lower (revert some changes, but let comments. Also fix DefaultFaceletContext.generateUniqueId for not include '-' chars on ids)

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlScriptRenderer.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlStylesheetRenderer.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/InsertChildrenHandler.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlScriptRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlScriptRenderer.java?rev=885951&r1=885950&r2=885951&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlScriptRenderer.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlScriptRenderer.java Tue Dec  1 21:42:59 2009
@@ -73,38 +73,38 @@
         {
             FacesContext facesContext = FacesContext.getCurrentInstance();
             
-            if (component.getId() != null)
-            {
-                UniqueIdVendor uiv = findParentUniqueIdVendor(component);
-
-                if ( (!(uiv instanceof UIViewRoot)) && component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
-                {
-                    // The id was set using the closest UniqueIdVendor, but since this one
-                    // will be relocated, we need to assign an id from the current root.
-                    // otherwise a duplicate id exception could happen.
-                    component.setId(facesContext.getViewRoot().createUniqueId(facesContext, null));
-                }
-            }
+            //if (component.getId() != null)
+            //{
+            //    UniqueIdVendor uiv = findParentUniqueIdVendor(component);
+            //
+            //    if ( (!(uiv instanceof UIViewRoot)) && component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
+            //    {
+            //        // The id was set using the closest UniqueIdVendor, but since this one
+            //        // will be relocated, we need to assign an id from the current root.
+            //        // otherwise a duplicate id exception could happen.
+            //        component.setId(facesContext.getViewRoot().createUniqueId(facesContext, null));
+            //    }
+            //}
 
             facesContext.getViewRoot().addComponentResource(facesContext,
                     component, target);
         }
     }
     
-    private static UniqueIdVendor findParentUniqueIdVendor(UIComponent component)
-    {
-        UIComponent parent = component.getParent();
-
-        while (parent != null)
-        {
-            if (parent instanceof UniqueIdVendor)
-            {
-                return (UniqueIdVendor) parent;
-            }
-            parent = parent.getParent();
-        }
-        return null;
-    }
+    //private static UniqueIdVendor findParentUniqueIdVendor(UIComponent component)
+    //{
+    //    UIComponent parent = component.getParent();
+    //
+    //    while (parent != null)
+    //    {
+    //        if (parent instanceof UniqueIdVendor)
+    //        {
+    //            return (UniqueIdVendor) parent;
+    //        }
+    //        parent = parent.getParent();
+    //    }
+    //    return null;
+    //}
 
     @Override
     public boolean getRendersChildren()

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlStylesheetRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlStylesheetRenderer.java?rev=885951&r1=885950&r2=885951&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlStylesheetRenderer.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlStylesheetRenderer.java Tue Dec  1 21:42:59 2009
@@ -70,37 +70,37 @@
         UIComponent component = event.getComponent();
         FacesContext facesContext = FacesContext.getCurrentInstance();
         
-        if (component.getId() != null)
-        {
-            UniqueIdVendor uiv = findParentUniqueIdVendor(component);
-            
-            if ( (!(uiv instanceof UIViewRoot)) && component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
-            {
-                // The id was set using the closest UniqueIdVendor, but since this one
-                // will be relocated, we need to assign an id from the current root.
-                // otherwise a duplicate id exception could happen.
-                component.setId(facesContext.getViewRoot().createUniqueId(facesContext, null));
-            }
-        }
+        //if (component.getId() != null)
+        //{
+        //    UniqueIdVendor uiv = findParentUniqueIdVendor(component);
+        //
+        //    if ( (!(uiv instanceof UIViewRoot)) && component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
+        //    {
+        //        // The id was set using the closest UniqueIdVendor, but since this one
+        //        // will be relocated, we need to assign an id from the current root.
+        //        // otherwise a duplicate id exception could happen.
+        //        component.setId(facesContext.getViewRoot().createUniqueId(facesContext, null));
+        //    }
+        //}
         
         facesContext.getViewRoot().addComponentResource(facesContext,
                     component, "head");
     }
     
-    private static UniqueIdVendor findParentUniqueIdVendor(UIComponent component)
-    {
-        UIComponent parent = component.getParent();
-
-        while (parent != null)
-        {
-            if (parent instanceof UniqueIdVendor)
-            {
-                return (UniqueIdVendor) parent;
-            }
-            parent = parent.getParent();
-        }
-        return null;
-    }
+    //private static UniqueIdVendor findParentUniqueIdVendor(UIComponent component)
+    //{
+    //    UIComponent parent = component.getParent();
+    //
+    //    while (parent != null)
+    //    {
+    //        if (parent instanceof UniqueIdVendor)
+    //        {
+    //            return (UniqueIdVendor) parent;
+    //        }
+    //        parent = parent.getParent();
+    //    }
+    //    return null;
+    //}
 
     @Override
     public boolean getRendersChildren()

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java?rev=885951&r1=885950&r2=885951&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java Tue Dec  1 21:42:59 2009
@@ -128,7 +128,7 @@
                     // UIViewRoot implements UniqueIdVendor, so there is no need to cast to UIViewRoot
                     // and call createUniqueId(). Also, note that UIViewRoot.createUniqueId() javadoc
                     // says we could send as seed the facelet generated id.
-                    String uid = uniqueIdVendor.createUniqueId(ctx.getFacesContext(), null);
+                    String uid = uniqueIdVendor.createUniqueId(ctx.getFacesContext(), id);
                     c.setId(uid);
                 }                
                 c.getAttributes().put(ComponentSupport.MARK_CREATED, id);

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java?rev=885951&r1=885950&r2=885951&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java Tue Dec  1 21:42:59 2009
@@ -225,15 +225,21 @@
 
         if (_prefix == null)
         {
-            // TODO: change to StringBuilder when JDK1.5 support is available
-            StringBuffer builder = new StringBuffer(
+            StringBuilder builder = new StringBuilder(
                     _faceletHierarchy.size() * 30);
             for (int i = 0; i < _faceletHierarchy.size(); i++)
             {
                 DefaultFacelet facelet = _faceletHierarchy.get(i);
                 builder.append(facelet.getAlias());
             }
-            Integer prefixInt = new Integer(builder.toString().hashCode());
+
+            // Integer prefixInt = new Integer(builder.toString().hashCode());
+            // -= Leonardo Uribe =- if the previous formula is used, it is possible that
+            // negative values are introduced. The presence of '-' char causes problems
+            // with htmlunit 2.4 or lower, so in order to prevent it it is better to use
+            // only positive values instead.
+            // Take into account CompilationManager.nextTagId() uses Math.abs too.
+            Integer prefixInt = new Integer(Math.abs(builder.toString().hashCode()));
 
             Integer cnt = _prefixes.get(prefixInt);
             if (cnt == null)

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/InsertChildrenHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/InsertChildrenHandler.java?rev=885951&r1=885950&r2=885951&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/InsertChildrenHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/InsertChildrenHandler.java Tue Dec  1 21:42:59 2009
@@ -91,16 +91,66 @@
             // point there is no any call to getClientId() yet. But it is better
             // let this code commented, because some day could be useful.
             //
-            //UIComponent uniqueIdVendor = (UIComponent) ComponentSupport.getClosestUniqueIdVendor(_targetComponent);
-            //
-            //if (uniqueIdVendor != null && !uniqueIdVendor.getClientId().equals(parentCompositeComponent.getClientId()))
-            //{
-                //Reset clientId calling setId()
-                //for (UIComponent child : childList)
-                //{
-                //    child.setId(child.getId());
-                //}
-            //}
+            /*
+            UIComponent uniqueIdVendor = (UIComponent) findParentUniqueIdVendor(_targetComponent);
+            
+            if (uniqueIdVendor != null && !uniqueIdVendor.getClientId().equals(parentCompositeComponent.getClientId()))
+            {
+                FacesContext facesContext = FacesContext.getCurrentInstance();
+                
+                for (UIComponent child : childList)
+                {
+                    regenerateUniqueIds(facesContext, (UniqueIdVendor) uniqueIdVendor, child);
+                }
+            }*/
+        }
+        
+        /*
+        private void regenerateUniqueIds(FacesContext facesContext, UniqueIdVendor uniqueIdVendor,  UIComponent comp)
+        {
+            if (comp.getId() != null && comp.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
+            {
+                //Assign a new generated id according to the new UniqueIdVendor parent 
+                comp.setId(((UniqueIdVendor)uniqueIdVendor).createUniqueId(facesContext, null));
+            }
+            
+            if (comp instanceof UniqueIdVendor)
+            {
+                uniqueIdVendor = (UniqueIdVendor) comp;
+            }
+
+            if (comp.getChildCount() > 0)
+            {
+                for (UIComponent child : comp.getChildren())
+                {
+                    regenerateUniqueIds(facesContext, uniqueIdVendor, child);
+                }
+            }
+            if (comp.getFacetCount() > 0)
+            {
+                for (UIComponent child : comp.getFacets().values())
+                {
+                    regenerateUniqueIds(facesContext, uniqueIdVendor, child);
+                }
+            }
+        }
+        */
+    }
+    
+    /*
+    private static UniqueIdVendor findParentUniqueIdVendor(UIComponent component)
+    {
+        UIComponent parent = component.getParent();
+
+        while (parent != null)
+        {
+            if (parent instanceof UniqueIdVendor)
+            {
+                return (UniqueIdVendor) parent;
+            }
+            parent = parent.getParent();
         }
+        return null;
     }
+    */
 }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java?rev=885951&r1=885950&r2=885951&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java Tue Dec  1 21:42:59 2009
@@ -177,7 +177,7 @@
                 {
                     // UIViewRoot implements UniqueIdVendor, so there is no need to cast to UIViewRoot
                     // and call createUniqueId()
-                    String uid = uniqueIdVendor.createUniqueId(facesContext, null);
+                    String uid = uniqueIdVendor.createUniqueId(facesContext, id);
                     c.setId(uid);
                 }
             }