myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r885664 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/html: HtmlScriptRenderer.java HtmlStylesheetRenderer.java
Date Tue, 01 Dec 2009 04:07:14 GMT
Author: lu4242
Date: Tue Dec  1 04:07:13 2009
New Revision: 885664

URL: http://svn.apache.org/viewvc?rev=885664&view=rev
Log:
MYFACES-2428 Id generation for facelets cause problems with htmlunit 2.4 or lower

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

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=885664&r1=885663&r2=885664&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 04:07:13 2009
@@ -28,6 +28,8 @@
 import javax.faces.application.ProjectStage;
 import javax.faces.application.Resource;
 import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.UniqueIdVendor;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 import javax.faces.event.ComponentSystemEvent;
@@ -70,10 +72,36 @@
         if (target != null)
         {
             FacesContext facesContext = FacesContext.getCurrentInstance();
+            
+            UniqueIdVendor uiv = findParentUniqueIdVendor(component);
+            
+            if (! (uiv instanceof UIViewRoot))
+            {
+                // 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;
+    }
 
     @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=885664&r1=885663&r2=885664&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 04:07:13 2009
@@ -28,6 +28,8 @@
 import javax.faces.application.ProjectStage;
 import javax.faces.application.Resource;
 import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.UniqueIdVendor;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 import javax.faces.event.ComponentSystemEvent;
@@ -67,9 +69,35 @@
     {
         UIComponent component = event.getComponent();
         FacesContext facesContext = FacesContext.getCurrentInstance();
+        
+        UniqueIdVendor uiv = findParentUniqueIdVendor(component);
+        
+        if (! (uiv instanceof UIViewRoot))
+        {
+            // 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;
+    }
 
     @Override
     public boolean getRendersChildren()



Mime
View raw message