[ 
http://issues.apache.org/jira/browse/MYFACES-425?page=comments#action_12320718 
] 

Ken Weiner commented on MYFACES-425:
------------------------------------

I don't know if we are *allowed*, but it seems to work :)  How would we find 
out if we're *allowed*?

> findUISelectManyConverter should look for converter when valueType is List
> --------------------------------------------------------------------------
>
>          Key: MYFACES-425
>          URL: http://issues.apache.org/jira/browse/MYFACES-425
>      Project: MyFaces
>         Type: Bug
>     Versions: Nightly Build
>     Reporter: Ken Weiner
>     Assignee: Martin Marinschek
>  Attachments: RendererUtils.patch.txt
>
> Currently the RendererUtils.findUISelectManyConverter() method assumes that, 
> when the valueType is a List, the List must contain Strings, and therefore no 
> Converter is needed.  If the valueType is an array, then this method attempts 
> to see if there is a Converter for the arrayComponentType (the type of 
> objects that the array holds).  A comment says that the API Doc of 
> UISelectMany assumes that the List holds Strings, but we have an opportunity 
> here to improve on that.
> The patch I'm submitting allows the binding of a UISelectMany component to a 
> List of objects other than Strings.  The behavior ends up being the same as 
> if we were binding to an array of some component whose type is not a String 
> (finding a Converter in this case is already handled by the 
> RendererUtils.findUISelectManyConverter() method.
> The code that I propose adding is listed here and a patch file will be 
> attached:
>         if (List.class.isAssignableFrom(valueType))
>         {
>             //According to API Doc of UISelectMany the assumed entry type for 
> a List is String
>             //--> 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);
>             if (selectItems != null && selectItems.size() > 0) {
>                 SelectItem selectItem = (SelectItem) selectItems.get(0);
>               Class listComponentType = selectItem.getValue().getClass();
>                 if (!(String.class.equals(listComponentType))) {
>                     try
>                     {
>                         return 
> facesContext.getApplication().createConverter(listComponentType);
>                     }
>                     catch (FacesException e)
>                     {
>                         log.error("No Converter for type " + 
> listComponentType.getName() + " found", e);
>                         return null;
>                     }
>                 }
>             }
>         }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to