• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

selectOneMenu

 
Jhonnathan Emilio Cardona Saineda
Ranch Hand
Posts: 38
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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...
 
Bharat Kasodariya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use 'valueChangeListener' attribute.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Tim¡¡¡¡¡¡¡ thank you very much, your explanation helped me
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic