Hi,

have a look at the sandbox ajaxChildComboBox. I think this is the one
which can help in your usecase:

http://example.irian.at/example-sandbox-20060822/ajaxChildComboBox.jsf

cheers,

Gerald

On 8/22/06, Andrew Robinson <[EMAIL PROTECTED]> wrote:
Depends on the level of functionality you need. The best thing to do
for user experience is to AJAX the combo boxes, so that when one
changes, you can reload the next one with the dependent values. For
this I would suggest researching a4j [1].

As for getting the selected item, the select one menu operates off of
value binding. Each select item has a value property. That value is
what is used to set the property of the select on value:

<t:selectOneMenu value="#{myBean.selectedItem}">
  <f:selectItems value="#{myBean.selectItems}" />
</t:selectOneMenu>

In this example, when the form is submitted (not when the combo
changes by default), the "myBean.setSelectedItem(Object)" method will
be called. You can use this setter or use an action to load the next
combo box.

Here is how it may look without AJAX (note that the clickLink java
script code can be found in the WIKI at [2]):

<t:commandLink actionListener="#{myBean.countryChanged}"
  style="visibility: hidden; display="none" id="onCountryChange"
forceId="true" />
<t:selectOneMenu
  onChange="clickLink('onCountryChange')"
  value="#{myBean.selectedCountry}">
  <f:selectItems value="#{myBean.countries}" />
</t:selectOneMenu>

<t:commandLink actionListener="#{myBean.stateChanged}"
  style="visibility: hidden; display="none" id="onStateChange" forceId="true" />
<t:selectOneMenu
  onChange="clickLink('onStateChange')"
  value="#{myBean.selectedState}">
  <f:selectItems value="#{myBean.statesForCurrentCountry}" />
</t:selectOneMenu>

As for the Java, I'd like to leave you something to figure out :-)

-Andrew

[1] https://ajax4jsf.dev.java.net/nonav/ajax/ajax-jsf/
[2] http://wiki.apache.org/myfaces/JavascriptWithJavaServerFaces

On 8/22/06, tukutela <[EMAIL PROTECTED]> wrote:
>
> I posted yesterday and got some great help, java forums are amazing, so many
> people offering advice.
>
> I've got a list of three selectonemenus I need to populate in descending
> order, country, state, then finally city, each are dependent on the other.
> I've created a country object (menu) which grabs data from the database and
> it works perfectly, however I don't know how to get the selectedItem from
> the list, and pass that value to the next state selectonemenu so it can in
> turn populate the states for that given country selected. I'm having some
> trouble scouring the web for examples, does anybody have anything that could
> help?
> --
> View this message in context: 
http://www.nabble.com/Hi-all%21-SelectOnMenu-Example-Needed-tf2146733.html#a5926994
> Sent from the MyFaces - Users forum at Nabble.com.
>
>



--
Gerald Müllan
Schelleingasse 2/11
1040 Vienna, Austria
0043 699 11772506
[EMAIL PROTECTED]

Reply via email to