• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I update the values in my selectOneMenu?

 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!