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/11/12 21:05:42 UTC

svn commit: r835520 - /myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/RendererUtils.java

Author: lu4242
Date: Thu Nov 12 20:05:42 2009
New Revision: 835520

URL: http://svn.apache.org/viewvc?rev=835520&view=rev
Log:
MYFACES-2136 UISelectMany (fix small bug)

Modified:
    myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/RendererUtils.java

Modified: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/RendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/RendererUtils.java?rev=835520&r1=835519&r2=835520&view=diff
==============================================================================
--- myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/RendererUtils.java (original)
+++ myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/RendererUtils.java Thu Nov 12 20:05:42 2009
@@ -25,6 +25,7 @@
 import java.io.Serializable;
 import java.lang.reflect.Array;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashSet;
@@ -406,7 +407,7 @@
 
 
     /**
-     * Find proper Converter for the entries in the associated List or Array of
+     * Find proper Converter for the entries in the associated Collection or array of
      * the given UISelectMany as specified in API Doc of UISelectMany.
      * @return the Converter or null if no Converter specified or needed
      * @throws FacesException if the Converter could not be created
@@ -414,61 +415,38 @@
     public static Converter findUISelectManyConverter(FacesContext facesContext,
                                                       UISelectMany component)
     {
+        // If the component has an attached Converter, use it.
         Converter converter = component.getConverter();
         if (converter != null) return converter;
 
-        //Try to find out by value binding
-        ValueExpression vb = component.getValueExpression("value");
-        if (vb == null) return null;
+        //Try to find out by value expression
+        ValueExpression ve = component.getValueExpression("value");
+        if (ve == null) return null;
 
-        //By some strange reason vb.getType(facesContext.getELContext());
-        //does not return the same as vb.getValue(facesContext.getELContext()).getClass(),
+        //By some strange reason ve.getType(facesContext.getELContext());
+        //does not return the same as ve.getValue(facesContext.getELContext()).getClass(),
         //so we need to use this instead.
-        Class valueType = null;
-        Object value = vb.getValue(facesContext.getELContext()); 
-        valueType = (value != null) ? value.getClass() :
-            vb.getType(facesContext.getELContext()) ;
+        Class<?> valueType = null;
+        Object value = ve.getValue(facesContext.getELContext()); 
+        valueType = (value != null) 
+                        ? value.getClass() 
+                        : ve.getType(facesContext.getELContext());
         
         if (valueType == null) return null;
         
-        if (List.class.isAssignableFrom(valueType))
+        if (Collection.class.isAssignableFrom(valueType))
         {
-            //According to API Doc of UISelectMany the assumed entry type for a List is String
-            //--> so basically no converter needed
-
-            // However, if the List contains something other than Strings, we can attempt
-            // to find a suitable converter. In JDK 1.4, we can try to find out what the List
-            // contains by looking at the SelectItem value of the first item. With generics in
-            // JDK 1.5, it would be much easier to determine the type.
-
-            List selectItems = RendererUtils.internalGetSelectItemList(component, facesContext);
-
-            if (selectItems != null && selectItems.size() > 0)
-            {
-                SelectItem selectItem = (SelectItem) selectItems.get(0);
-                Class listComponentType = selectItem.getValue().getClass();
-
-                    try
-                    {
-                        return facesContext.getApplication().createConverter(listComponentType);
-                    }
-                    catch (FacesException e)
-                    {
-                        log.log(Level.SEVERE, "No Converter for type " + listComponentType.getName() + " found", e);
-                        return null;
-                    }
-
-            }
-
+            // Spec: do not convert the values
             return null;
         }
 
         if (!valueType.isArray())
         {
-            throw new IllegalArgumentException("ValueBinding for UISelectMany : "+getPathToComponent(component)+" must be of type List or Array");
+            throw new IllegalArgumentException("ValueExpression for UISelectMany : "
+                    + getPathToComponent(component) + " must be of type Collection or array");
         }
 
-        Class arrayComponentType = valueType.getComponentType();
+        Class<?> arrayComponentType = valueType.getComponentType();
         if (String.class.equals(arrayComponentType)) return null;    //No converter needed for String type
         if (Object.class.equals(arrayComponentType)) return null;    //There is no converter for Object class