You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by David Delbecq <de...@oma.be> on 2007/06/14 15:12:04 UTC

SelectOneMenu and null value

Hello,

I have a design where, in the select list of SelectOneMenu, i need to
set a blank entry for null value.

For now, i set it up like this

1) the list of available options contain an entry with label="" and
value="[nothing]"
2) A converter is set to this list (based on value class). From
"[nothing]", getAsObject returns null. From a null or an empty String,
getAsString returns "[nothing]". Since SelectOneMenu uses the String to
compare the list items to currentValue, this shouldn't pose problem. I
have seen this solution proposed at several places on the web.

This works nearly perfectly.

1) I can select the blank entry (even if baking bean already has a non
null value), it success validation of component and copy null value to
'localeValue' of UIComponent, that will then be put in backingbean.
2) I can select the blank entry and call an immediate action, the
submitted value is kept and, upon form, redisplay it correctly mark the
blank one as 'selected'

But it fails in this conditions
1) There is already a value in backing bean for this selectOneMenu and i
didn't yet change it  in form (so localValue is not yet set!)
2) There are other component in form
Now if during the same submit i choose the blank value and set a value
in another component that will fail validation, after the validation
error, the selected item is rolled back to previous one.

Note, this error does not happen if i first change the entry to another
one, call an immediate action (now localValue is set and is something
else than null) and then reprocess to the failing operation.

Anybody have any idea why, from time to time, the value change is
ignored (not anymore in submitted, not in localValue)? This is very
annoying as it looks to user like random partial form reset during
validation, reset which happen in fields not marked has having
validation errors.

Regards,
David Delbecq

Re: SelectOneMenu and null value

Posted by David Delbecq <de...@oma.be>.
Self responding as i have not friends, you know how it is, too much job,
too much geeky, no friend to send you postcard or birthday cards....


Just to tell list and potential future seekers, it seems this problem
was fixed in svn, upgrading from 1.1.5 to 1.1.6-SNAPSHOT fixes the issue.

En l'instant précis du 14/06/07 15:12, David Delbecq s'exprimait en ces
termes:
> Hello,
>
> I have a design where, in the select list of SelectOneMenu, i need to
> set a blank entry for null value.
>
> For now, i set it up like this
>
> 1) the list of available options contain an entry with label="" and
> value="[nothing]"
> 2) A converter is set to this list (based on value class). From
> "[nothing]", getAsObject returns null. From a null or an empty String,
> getAsString returns "[nothing]". Since SelectOneMenu uses the String to
> compare the list items to currentValue, this shouldn't pose problem. I
> have seen this solution proposed at several places on the web.
>
> This works nearly perfectly.
>
> 1) I can select the blank entry (even if baking bean already has a non
> null value), it success validation of component and copy null value to
> 'localeValue' of UIComponent, that will then be put in backingbean.
> 2) I can select the blank entry and call an immediate action, the
> submitted value is kept and, upon form, redisplay it correctly mark the
> blank one as 'selected'
>
> But it fails in this conditions
> 1) There is already a value in backing bean for this selectOneMenu and i
> didn't yet change it  in form (so localValue is not yet set!)
> 2) There are other component in form
> Now if during the same submit i choose the blank value and set a value
> in another component that will fail validation, after the validation
> error, the selected item is rolled back to previous one.
>
> Note, this error does not happen if i first change the entry to another
> one, call an immediate action (now localValue is set and is something
> else than null) and then reprocess to the failing operation.
>
> Anybody have any idea why, from time to time, the value change is
> ignored (not anymore in submitted, not in localValue)? This is very
> annoying as it looks to user like random partial form reset during
> validation, reset which happen in fields not marked has having
> validation errors.
>
> Regards,
> David Delbecq
>