I have a selectOneListbox that is working just fine. However, after validation and when an error is found on the page, the page shows the values of all the fields but the dropdown lists do not show the selected value in the dropdown. The dropdown reverts to the default selected value.
Can someone tell me how to correct this behavior so that after validation the dropdowns display the selected values initially selected in the form?
Any help/direction would be greatly appreciated.
Here is one of the dropdowns in my form and how it is defined in my JSP page:
I am not sure if this tidbit helps or not but in another forum I was told that the scope of my backing bean maybe the issue(?). I have the scope set to "session" and not request. Could this be the problem?
Any help here would be greatly appreciated. I am stuck here.
You need a valueChangeListener on your selectOneListbox.
When validation fails, certain components never make it to the backing bean, so you want to bypass validation for this component by using the immediate attribute.
According to docs I've read, immediate events are fired after the "Apply Request Values" phase, which is before "Process Validations".
I forgot one thing. In your valueChangeListener method, you'll have to get the current instance of the FacesContext and then call renderResponse() in that method. That will skip the rest of the life cycle. Doing this costs you a server roundtrip, but I don't know of another way. Maybe someone else might.
Leo - I tried creating a valueChangeListener method as indicated below:
In my JSP I added this method as you stated above (sorry I'm working with a different dropdown that I initially put in my post above but it's the same thing):
When I run the code the new method is run first before any validations are done but what happens is that the page is reloaded the dropdown still does NOT show the selected value. Apparently I'm doing something wrong. I'll check the setter again perhaps that is where my problem is.
I hope I'm going down the correct path here. Thank you.
Leo. Question, as I am still having the same issue.
What did you put in the selectionChanged() you have below:
Here is what I had put in my valueChangeListener method:
I put in the value and value2 just to see if the values were still populated AFTER the FacesContext.getCurrentInstance().getRenderResponse() since after my page reloads the dropdown box is still NOT selected.
Here is what is in my JSP page for this selectOneListbox:
I know I must be missing something but I'm just not sure what. I tried your example and the only this is that my list is getting populated via the database which should NOT be an issue.
Here is the code as to how I'm populating my dropdown:
It is just returning a simple list. I just cannot seem to find what my problem is. Thanks again for your help.