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/06 13:22:25 UTC

svn commit: r354412 - in /myfaces/tomahawk/trunk/src/java/org/apache/myfaces/component/html: ext/HtmlSelectOneRadio.java util/HtmlComponentUtils.java

Author: mmarinschek
Date: Tue Dec  6 04:22:18 2005
New Revision: 354412

URL: http://svn.apache.org/viewcvs?rev=354412&view=rev
Log:
fix for MYFACES-902. thanks to alvin antony

Modified:
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/component/html/ext/HtmlSelectOneRadio.java
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/component/html/util/HtmlComponentUtils.java

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/component/html/ext/HtmlSelectOneRadio.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/component/html/ext/HtmlSelectOneRadio.java?rev=354412&r1=354411&r2=354412&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/component/html/ext/HtmlSelectOneRadio.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/component/html/ext/HtmlSelectOneRadio.java Tue Dec  6 04:22:18 2005
@@ -17,14 +17,6 @@
 
 import java.util.Iterator;
 
-import org.apache.myfaces.component.DisplayValueOnlyCapable;
-import org.apache.myfaces.component.EscapeCapable;
-import org.apache.myfaces.component.UserRoleAware;
-import org.apache.myfaces.component.UserRoleUtils;
-import org.apache.myfaces.component.html.util.HtmlComponentUtils;
-import org.apache.myfaces.util.MessageUtils;
-import org.apache.myfaces.util._ComponentUtils;
-
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIInput;
 import javax.faces.context.FacesContext;
@@ -34,15 +26,28 @@
 import javax.faces.validator.Validator;
 import javax.faces.validator.ValidatorException;
 
+import org.apache.myfaces.component.DisplayValueOnlyCapable;
+
+import org.apache.myfaces.component.UserRoleAware;
+import org.apache.myfaces.component.UserRoleUtils;
+import org.apache.myfaces.component.html.util.HtmlComponentUtils;
+import org.apache.myfaces.renderkit.JSFAttr;
+import org.apache.myfaces.util.MessageUtils;
+import org.apache.myfaces.util._ComponentUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 /**
  * @author Manfred Geiler (latest modification by $Author$)
  * @version $Revision$ $Date$
  */
 public class HtmlSelectOneRadio
         extends javax.faces.component.html.HtmlSelectOneRadio
-        implements UserRoleAware, DisplayValueOnlyCapable, EscapeCapable
+        implements UserRoleAware, DisplayValueOnlyCapable
 {
-		public String getClientId(FacesContext context)
+    private static Log log = LogFactory.getLog(HtmlSelectOneRadio.class);
+
+    public String getClientId(FacesContext context)
     {
         String clientId = HtmlComponentUtils.getClientId(this, getRenderer(context), context);
         if (clientId == null)
@@ -53,18 +58,22 @@
         return clientId;
     }
 
-		/**
-     * Overridden method, as with extended seletOne, value doesn't necessaraly
+    /**
+     * Overridden method, as with extended seletOne, value doesn't necessarily
      * have to be contained within select list, for example, when forceId="true" and
      * forceIdIndex="false" then component may be used in datatable.
      */
     protected void validateValue(FacesContext context, Object value)
     {
         //Is this radio button used within a datatable (forceId=true and forceIdIndex=false)
-        Boolean forceId = (Boolean) this.getAttributes().get("forceId");
-        Boolean forceIdIndex = (Boolean) this.getAttributes().get("forceIdIndex");
-        boolean dataTable = forceId != null && forceId.booleanValue()
-                && !(forceIdIndex != null && forceIdIndex.booleanValue());
+        boolean forceId = getBooleanValue(JSFAttr.FORCE_ID_ATTR,
+                this.getAttributes().get(JSFAttr.FORCE_ID_ATTR), false);
+
+//      see if the originally supplied id should be used
+        boolean forceIdIndex = getBooleanValue(JSFAttr.FORCE_ID_INDEX_ATTR,
+                this.getAttributes().get(JSFAttr.FORCE_ID_INDEX_ATTR), true);
+
+        boolean dataTable = forceId && !forceIdIndex;
 
         if (!dataTable)
         {
@@ -94,7 +103,7 @@
             		message.setSeverity(FacesMessage.SEVERITY_WARN);
             		context.addMessage(clientId, message);
 
-                setValid(false);
+                    setValid(false);
             	}
                 return;
             }
@@ -107,6 +116,28 @@
         }
     }
 
+
+    private static boolean getBooleanValue(String attribute, Object value, boolean defaultValue)
+    {
+        if(value instanceof Boolean)
+        {
+            return ((Boolean) value).booleanValue();
+        }
+        else if(value instanceof String)
+        {
+            return Boolean.valueOf((String) value).booleanValue();
+        }
+        else if(value != null)
+        {
+            log.error("value for attribute "+attribute+
+                    " must be instanceof 'Boolean' or 'String', is of type : "+value.getClass());
+
+            return defaultValue;
+        }
+
+        return defaultValue;
+    }
+
     private static void callValidators(FacesContext context, UIInput input, Object convertedValue)
     {
         Validator[] validators = input.getValidators();
@@ -165,8 +196,8 @@
     private String _enabledOnUserRole = null;
     private String _visibleOnUserRole = null;
     private Boolean _displayValueOnly = null;
-	private String _displayValueOnlyStyle = null;
-	private String _displayValueOnlyStyleClass = null;
+    private String _displayValueOnlyStyle = null;
+    private String _displayValueOnlyStyleClass = null;
 
     public HtmlSelectOneRadio()
     {
@@ -264,20 +295,4 @@
         _displayValueOnlyStyleClass = (String)values[5];
     }
     //------------------ GENERATED CODE END ---------------------------------------
-
-    private Boolean _escape = null;
-    private static final boolean DEFAULT_ESCAPE = true;
-
-    public void setEscape(boolean escape)
-    {
-        _escape = Boolean.valueOf(escape);
-    }
-
-    public boolean isEscape()
-    {
-        if (_escape != null) return _escape.booleanValue();
-        ValueBinding vb = getValueBinding("escape");
-        Boolean v = vb != null ? (Boolean)vb.getValue(getFacesContext()) : null;
-        return v != null ? v.booleanValue() : DEFAULT_ESCAPE;
-    }
 }

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/component/html/util/HtmlComponentUtils.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/component/html/util/HtmlComponentUtils.java?rev=354412&r1=354411&r2=354412&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/component/html/util/HtmlComponentUtils.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/component/html/util/HtmlComponentUtils.java Tue Dec  6 04:22:18 2005
@@ -22,6 +22,8 @@
 import javax.faces.render.Renderer;
 
 import org.apache.myfaces.renderkit.JSFAttr;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * <p>Utility class for providing basic functionality to the HTML faces 
@@ -30,15 +32,16 @@
  * @author Sean Schofield
  * @version $Revision$ $Date$
  */
-public class HtmlComponentUtils 
+public class HtmlComponentUtils
 {
-    
+    private static Log log = LogFactory.getLog(HtmlComponentUtils.class);
+
     /**
      * Constructor (Private)
      */
-    private HtmlComponentUtils() 
+    private HtmlComponentUtils()
     {}
-    
+
     /**
      * Gets the client id associated with the component.  Checks the forceId 
      * attribute of the component (if present) and uses the orginally supplied 
@@ -50,39 +53,19 @@
      * @param context Additional context information to help in the request.
      * @return The clientId to use with the specified component.
      */
-    public static String getClientId(UIComponent component, 
-                                     Renderer renderer, 
+    public static String getClientId(UIComponent component,
+                                     Renderer renderer,
                                      FacesContext context)
     {
-        // see if the originally supplied id should be used 
-        Boolean forceValue = null;
 
-        Object forceValueObj = component.getAttributes().get(JSFAttr.FORCE_ID_ATTR);
-
-        if(forceValueObj instanceof Boolean)
-        {
-            forceValue = (Boolean)forceValueObj;
-        }
-        else if(forceValueObj instanceof String)
-        {
-            forceValue = Boolean.valueOf((String) forceValueObj);
-        }
-        else if(forceValueObj != null)
-        {
-            throw new IllegalStateException("forceId must be instanceof 'Boolean' or 'String'");
-        }
+        //forceId enabled?
+        boolean forceId = getBooleanValue(JSFAttr.FORCE_ID_ATTR,
+                component.getAttributes().get(JSFAttr.FORCE_ID_ATTR),false);
 
-        boolean forceId = false;
-        
-        if (forceValue != null)
-        {
-            forceId = forceValue.booleanValue();
-        }        
-        
         if (forceId && component.getId() != null)
         {
             String clientId = component.getId();
-            
+
             /**
              * See if there is a parent naming container.  If there is ...
              */
@@ -91,14 +74,9 @@
             {
                 if (parentContainer instanceof UIData)
                 {
-                    // see if the originally supplied id should be used 
-                    Boolean forceIdIndexValue = (Boolean)component.getAttributes().get(JSFAttr.FORCE_ID_INDEX_ATTR);
-                    boolean forceIdIndex = true;
-
-                    if (forceIdIndexValue != null)
-                    {
-                        forceIdIndex = forceIdIndexValue.booleanValue();
-                    }        
+                    // see if the originally supplied id should be used
+                    boolean forceIdIndex = getBooleanValue(JSFAttr.FORCE_ID_ATTR,
+                            component.getAttributes().get(JSFAttr.FORCE_ID_INDEX_ATTR),true);
 
                     // note: user may have specifically requested that we do not add the special forceId [index] suffix
                     if (forceIdIndex)
@@ -110,13 +88,13 @@
                     }
                 }
             }
-            
+
             // JSF spec requires that renderer get a chance to convert the id
             if (renderer != null)
             {
                 clientId = renderer.convertClientId(context, clientId);
             }
-            
+
             return clientId;
         }
         else
@@ -124,7 +102,28 @@
             return null;
         }
     }
-    
+
+    private static boolean getBooleanValue(String attribute, Object value, boolean defaultValue)
+    {
+        if(value instanceof Boolean)
+        {
+            return ((Boolean) value).booleanValue();
+        }
+        else if(value instanceof String)
+        {
+            return Boolean.valueOf((String) value).booleanValue();
+        }
+        else if(value != null)
+        {
+            log.error("value for attribute "+attribute+
+                    " must be instanceof 'Boolean' or 'String', is of type : "+value.getClass());
+
+            return defaultValue;
+        }
+
+        return defaultValue;
+    }
+
     /**
      * Locates the {@link NamingContainer} associated with the givem 
      * {@link UIComponent}.
@@ -134,8 +133,8 @@
      *    if no naming container is found.
      * @return The parent naming container (or root if applicable).
      */
-    public static UIComponent findParentNamingContainer(UIComponent component, 
-        boolean returnRootIfNotFound)
+    public static UIComponent findParentNamingContainer(UIComponent component,
+                                                        boolean returnRootIfNotFound)
     {
         UIComponent parent = component.getParent();
         if (returnRootIfNotFound && parent == null)
@@ -160,5 +159,5 @@
             }
         }
         return null;
-    }    
+    }
 }