• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How do I update the values in my selectOneMenu?

 
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Thanks tiny ad, for helping me escape the terrible comfort of this chair.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic