You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2005/12/04 01:27:28 UTC

svn commit: r352055 - /myfaces/impl/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlLabelRenderer.java

Author: mmarinschek
Date: Sat Dec  3 16:27:21 2005
New Revision: 352055

URL: http://svn.apache.org/viewcvs?rev=352055&view=rev
Log:
made the client-id lookup algorithm usable for extending classes

Modified:
    myfaces/impl/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlLabelRenderer.java

Modified: myfaces/impl/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlLabelRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/impl/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlLabelRenderer.java?rev=352055&r1=352054&r2=352055&view=diff
==============================================================================
--- myfaces/impl/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlLabelRenderer.java (original)
+++ myfaces/impl/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlLabelRenderer.java Sat Dec  3 16:27:21 2005
@@ -57,38 +57,9 @@
         String forAttr = getFor(uiComponent);
 
         if (forAttr != null)
-            {
-            UIComponent forComponent = uiComponent.findComponent(forAttr);
-            if (forComponent == null)
-            {
-                if (log.isWarnEnabled())
-                {
-                    log.warn("Unable to find component '" + forAttr + "' (calling findComponent on component '" + uiComponent.getClientId(facesContext) + "')");
-                }
-                if (forAttr.length() > 0 && forAttr.charAt(0) == UINamingContainer.SEPARATOR_CHAR)
-                {
-                    //absolute id path
-                    writer.writeAttribute(HTML.FOR_ATTR, forAttr.substring(1), JSFAttr.FOR_ATTR);
-                }
-                else
-                {
-                    //relative id path, we assume a component on the same level as the label component
-                    String labelClientId = uiComponent.getClientId(facesContext);
-                    int colon = labelClientId.lastIndexOf(UINamingContainer.SEPARATOR_CHAR);
-                    if (colon == -1)
-                    {
-                        writer.writeAttribute(HTML.FOR_ATTR, forAttr, JSFAttr.FOR_ATTR);
-                    }
-                    else
-                    {
-                        writer.writeAttribute(HTML.FOR_ATTR, labelClientId.substring(0, colon + 1) + forAttr, JSFAttr.FOR_ATTR);
-                    }
-                }
-            }
-            else
-            {
-                writer.writeAttribute(HTML.FOR_ATTR, forComponent.getClientId(facesContext), JSFAttr.FOR_ATTR);
-            }
+        {
+          writer.writeAttribute(HTML.FOR_ATTR,
+                  getClientId(facesContext, uiComponent, forAttr), JSFAttr.FOR_ATTR);
         } 
         else 
         {
@@ -134,6 +105,46 @@
         else
         {
             return (String)component.getAttributes().get(JSFAttr.FOR_ATTR);
+        }
+    }
+    
+    protected String getClientId(FacesContext facesContext,
+                                 UIComponent uiComponent, String forAttr)
+    {
+        UIComponent forComponent = uiComponent.findComponent(forAttr);
+        if (forComponent == null)
+        {
+            if (log.isInfoEnabled())
+            {
+                log.info("Unable to find component '" + forAttr +
+                        "' (calling findComponent on component '" + uiComponent.getClientId(facesContext) + "')."+
+                        " We'll try to render out a guessed client-id anyways -"+
+                        " this will be a problem if you put a for-component and its corresponding input "+
+                        " in different naming-containers. If this is the case, you can always use the full client-id.");
+            }
+            if (forAttr.length() > 0 && forAttr.charAt(0) == UINamingContainer.SEPARATOR_CHAR)
+            {
+                //absolute id path
+                return forAttr.substring(1);
+            }
+            else
+            {
+                //relative id path, we assume a component on the same level as the label component
+                String labelClientId = uiComponent.getClientId(facesContext);
+                int colon = labelClientId.lastIndexOf(UINamingContainer.SEPARATOR_CHAR);
+                if (colon == -1)
+                {
+                    return forAttr;
+                }
+                else
+                {
+                    return labelClientId.substring(0, colon + 1);
+                }
+            }
+        }
+        else
+        {
+            return forComponent.getClientId(facesContext);
         }
     }