You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Daniel Campagnoli (JIRA)" <de...@myfaces.apache.org> on 2006/11/06 10:25:38 UTC

[jira] Commented: (MYFACES-1328) UISelectOne and UISelectMany fail with custom converter that returns java.lang.String from getAsObject() method.

    [ http://issues.apache.org/jira/browse/MYFACES-1328?page=comments#action_12447399 ] 
            
Daniel Campagnoli commented on MYFACES-1328:
--------------------------------------------

We are one of the many spoilt users that rely on the convenient conversion! We would be dissapointed to see this behaviour go as convenience is a good thing. We had just updated to the latest nightly build and it's broken our application.

I've had a look at the _SelectItemsUtil class, and it appears the problem could be solved by re-ordering the extra conversion to be after the initial equals check, which wouldn't break with custom converters that return String's. So the code snipped in this issues description would be replaced with: 

                Object itemValue = item.getValue(); 
                if (value==itemValue || value.equals(itemValue)) 
                { 
                    return true; 
                } 
               if(convenientConversion) // optional if statement so the default behaviour could match the RI
                {
                      if(converter != null && itemValue instanceof String) 
                      { 
                          itemValue = converter.getConvertedValue(context, (String)itemValue); 
                           if (value==itemValue || value.equals(itemValue)) 
                           { 
                                return true; 
                           } 
                      }    
                 }

The faces context and converter arguments would have to be added back to the matchValue() method and creation of the _ValueConverter in UISelectMany added back in.

Dan

> UISelectOne and UISelectMany fail with custom converter that returns java.lang.String from getAsObject() method.
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: MYFACES-1328
>                 URL: http://issues.apache.org/jira/browse/MYFACES-1328
>             Project: MyFaces Core
>          Issue Type: Bug
>    Affects Versions: 1.1.4-SNAPSHOT
>            Reporter: Alexey Maslov
>         Assigned To: Martin Marinschek
>             Fix For: 1.1.5-SNAPSHOT
>
>         Attachments: reproducer.zip
>
>
> The problem seems to be in javax.faces.component._SelectItemsUtil.matchValue(FacesContext context, Object value, Iterator selectItemsIter, _ValueConverter converter) method.
> Line 63-72:
>                 Object itemValue = item.getValue();
>                 if(converter != null && itemValue instanceof String)
>                 {
>                     itemValue = converter.getConvertedValue(context, (String)itemValue);
>                 }
>                 if (value==itemValue || value.equals(itemValue))
>                 {
>                     return true;
>                 }
> If item's value is java.lang.String then this code does duplicate conversion making matchValue() return false and subsequently resulting in error in calling method (validateValue() in javax.faces.component.UISelectOne and javax.faces.component.UISelectMany).

-- 
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