You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Alexander Staff <al...@astaff.de> on 2008/07/15 13:07:05 UTC

set selectOneMenu from bean

Hi,
I initially set a selectOneMenu (with selectItems-List) to a non-valid 
default-value. In my validator I check the contents and inform the user 
about the invalid values. BUT! I also set some valid values in the 
corresponding bean.
Problem: the value set in the bean are not displayed in the UI. There is 
always the old, invalid value.
How can I overwrite the values (the selected item resp.) in my validator 
that it is displayed in the ui.

Thanks
Ciao
Alexander

Re: set selectOneMenu from bean

Posted by "simon.kitching@chello.at" <si...@chello.at>.
Alexander Staff schrieb:
> Hi,
> I initially set a selectOneMenu (with selectItems-List) to a non-valid 
> default-value. In my validator I check the contents and inform the 
> user about the invalid values. BUT! I also set some valid values in 
> the corresponding bean.
> Problem: the value set in the bean are not displayed in the UI. There 
> is always the old, invalid value.
> How can I overwrite the values (the selected item resp.) in my 
> validator that it is displayed in the ui.
I presume that the "old" values are being shown by input components. 
Input components have an internal "submittedValue" property that 
deliberately does not get cleared unless the "update model" phase runs 
(which only happens when every component in the submitted form is 
valid). This is part of the JSF specification.

What you are doing is not generally recommended practice; setting stuff 
from validators can cause problems (as you have found out). I suggest 
you try to find an alternative way to solve your problem. But if you 
really really need to do that, then you will also need to find the 
various input component instances that you want to explicitly "refresh" 
and clear their submittedValue property. Perhaps the findComponent 
method can help there - or component bindings (yecch).

I'm pretty sure there is more information on this on the myfaces wiki 
somewhere, perhaps in the FAQ.

Regards, Simon