aspose file tools
The moose likes JSF and the fly likes How do I update the values in my selectOneMenu? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "How do I update the values in my selectOneMenu?" Watch "How do I update the values in my selectOneMenu?" New topic
Author

How do I update the values in my selectOneMenu?

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 434
Hi,

I'm using MyFaces 1.1.6. I have a select menu, whose options I want to change depending on the value entered in a text field . Note that I don't want to wait to submit the form, after the user triggers the onblur event from the textbox, I want the select values to change . How do I achieve this in JSF? I tried using simple Javascript, but when I do eventually submit my form, I get a "Value is not a valid option" error.

Thanks for the help, - Dave
Rajneesh K Rajput
Greenhorn

Joined: Nov 14, 2009
Posts: 10
Yes, it is expected that "Value is not a valid option" will be shown because you have changed the value options using Java Script, and when page gets submitted JSF restore the view and this new selected value might not be matching with any of the previous options.

So, what you need to do is you need to change mechanism (where values are dependent, textbox value), which is responsible to update the values at server side not only client side just by using Java Script, so that in restore phase it always aware of with the last entered value in the text field.

1) Please check- t:saveState and try binding text field value with t:saveState and make sure that while generating values for dropdown it picks text filed value from binding variable.

OR
2) Use some in-build Ajax framework, like RichFaces very powerful for JSF to implement such features using ajaxSubmit tag.
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 434
Rajneesh, Thanks for the reply but I'm not understanding what you are explaining. How do I use t:saveState to re-populate the selectOneMenu when the value of my h:inputText field changes? Any more detail you can provide is greatly appreciated, - Dave
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How do I update the values in my selectOneMenu?
 
Similar Threads
referencing a variable in a jsp from a servlet
How to keep a button from submitting a form.
Avoiding form resubmission
How to set values in select box using request scope
combo and text box