myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leonardo Uribe (JIRA)" <>
Subject [jira] Updated: (MYFACES-2927) Invalid handling of null values in listboxes and menus
Date Wed, 01 Dec 2010 16:01:15 GMT


Leonardo Uribe updated MYFACES-2927:

       Resolution: Fixed
    Fix Version/s: 2.0.3-SNAPSHOT
         Assignee: Leonardo Uribe
           Status: Resolved  (was: Patch Available)

I checked it and it is correct. Just one small note, to work correctly it requires:


param set to true to work as expected (otherwise it will thrown an exception because the String
is not a Enum value).

I did a test on mojarra 2.0.3 and it seems there h:selectOneMenu does not call getAsString
on the example, but in my opinion myfaces is doing right, always calling it and instead using
a param to control this behavior.

Thanks to Christian Kaltepoth for provide this patch.

> Invalid handling of null values in listboxes and menus
> ------------------------------------------------------
>                 Key: MYFACES-2927
>                 URL:
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: General
>    Affects Versions: 2.0.1
>            Reporter: Christian Kaltepoth
>            Assignee: Leonardo Uribe
>             Fix For: 2.0.3-SNAPSHOT
>         Attachments: MYFACES-2927.patch
> I discovered that MyFaces doesn't seem to handle null values correctly in listboxes and
> See the following example showing a h:selectOneMenu used to select an enum value:
>   @ManagedBean
>   @RequestScoped
>   public class TestBean {
>      public enum Level {
>         HIGH, MEDIUM, LOW
>      }
>      private Level level;
>      public String action() {
>         FacesContext.getCurrentInstance().addMessage(null, 
>               new FacesMessage("Submitted level: " + level));
>         return null;
>      }
>   }
> And the following view:
>   <h:selectOneMenu value="#{testBean.level}" label="Level">
>     <f:selectItem itemValue="#{null}" itemLabel="Unknown"/>
>     <f:selectItem itemValue="HIGH"    itemLabel="High"/>
>     <f:selectItem itemValue="MEDIUM"  itemLabel="Medium"/>
>     <f:selectItem itemValue="LOW"     itemLabel="Level"/>
>   </h:selectOneMenu>
>   <h:commandButton action="#{testBean.action}" value="Go"/>
> Clicking the "Go" button will result in the validation error: "Level: 'Unknown' must
be convertible to an enum."
> If the value of the select item is null, MyFaces won't render the value attribute of
the option and so the browser will submit the label as its value:
>   <select id="levelForm:level" name="levelForm:level" size="1">	
>     <option selected="selected">Unknown</option>	
>     <option value="HIGH">High</option>	
>     <option value="MEDIUM">Medium</option>	
>     <option value="LOW">Level</option>
>   </select>
> Mojarra instead renders an empty value attribute in this situation:
>   <option value="" selected="selected">Unknown</option>
> I've created a patch fixing this issue against the current trunk of myfaces-shared and
attached it to this ticket.
> You can see the sample application reproducing this issue here:
> And download it here:

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message