• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

selectOneMenu

  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

what i need is that when a user choose a country, automaticaly can add a cities based in the country, but I don't find an attribute in the selectOneMenu as the action of the comandButton that triggers an event and so i can load the cities.

How can launch an event from the selectOneMenu when chosen country?

<h:selectOneMenu id="m">
<f:selectItems value="#{ejemploBB.myList1}" />
</h:selectOneMenu>


<h:selectOneMenu id="m1">
<f:selectItems value="#{ejemploBB.myList2}" />
</h:selectOneMenu>


thanks...
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use 'valueChangeListener' attribute.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason you couldn't find anything is that until JSF 2, there wasn't any pretty way to do that.

JSF is built on HTTP and HTTP is not a continuous-conversation protocol. In other words, when you change control values, no actual network communications occur between client and server until an actual form submit is done. That is, the user clicks on a commandButton or commandLink.

So in order to make a menu selection submit a form, you'd need to add an "onchange" event attribute to the parent selection list. That onchange javascript would then "click the submit button".

But submitting an entire page is slow and ugly.

To make things more friendly, what's needed is AJAX. AJAX allows submitting just part of the page and in response updating only part(s) of the page. In particular, you'd want to update the child selection control based on the selection of the parent selection control.

There are 3 ways to do this. One is to use a set of custom extension tags with AJAX support in them such as RichFaces or IceFaces. That was the cleanest way to do things in JSF 1.x. In JSF2, the core tagset collection added an AJAX tag. The third way is the least-desirable way, since it involves writing your own JavaScript AJAX code, although use of a packaged solution such as jQuery can help.

I have found that the easiest way to get a dependent list control to follow changes to its parent selection is to write the "get" accessor for the child control's selectItems in a way where if there's no current list of selectitems, a list is created based on whatever the parent selection is. So what I do is make the value "set" method for the parent invalidate the child selectItem list, which causes a new, updated selectItem list to be built when the child control is re-rendered. It's also important when doing this to reset the current selection value for the child control, since the original selection value may not be referring to a valid value in the new selection list.
 
Jhonnathan Emilio Cardona Saineda
Ranch Hand
Posts: 38
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim¡¡¡¡¡¡¡ thank you very much, your explanation helped me
 
reply
    Bookmark Topic Watch Topic
  • New Topic