how to control one SelectOneMenu from another

I am trying to control one SelectOneMenu fron an other one. Like i have a situation where when a user selct country name from the county list than the SelectOneMenu of cities of that country should be activated.Do any one knows the solution
[254 byte] By [Atiqea] at [2007-11-26 14:56:09]
# 1
Please define "activated". Show hidden prepopulated list? Or submit, populate and show? Should this be done onchange or onsubmit?Should this all be done synchronous (JSF) or asynchronous (AJAX4JSF)?
BalusCa at 2007-7-8 8:44:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thanks for replying. from activate i mean to populate it. like if user select USA than the city list should populate cities in it. and it should be done onchange. i have not worked on ajax yet so i do not have any idea about it. so if you can provide me any solution for jsf i be very glad.

or

if there is any tutorial available for ajax solution so let me know it.

Atiqea at 2007-7-8 8:44:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

JSF<h:form>

<h:selectOneMenu value="#{myBean.selectedCountry}" onchange="submit();" valueChangeListener="#{myBean.loadCities}">

<f:selectItems value="#{myBean.selectCountries}" />

</h:selectOneMenu>

<h:selectOneMenu value="#{myBean.selectedCity}">

<f:selectItems value="#{myBean.selectCities}" />

</h:selectOneMenu>

</h:form>

MyBeanpublic void loadCities(ValueChangeEvent event) {

// Here you can get the selected country from selectedCountry and then populate selectCities.

}

BalusCa at 2007-7-8 8:44:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Thanks for this solution. I'll try it.

Now i am facing an other problem. that is i am using <h: message> tag to show error message if user do not enter value for any field. i have three button on my form .

1. Save

2. Clear

3. Edit

I want that <H:message will only validate when i press save button. but it also validate when i press clear or edit. so do you have any idea about it.>

Atiqea at 2007-7-8 8:44:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Add immediate="true" to the other buttons. Then all UIInput fields of the same form will be ignored. Also see http://balusc.xs4all.nl/srv/dev-jep-djl.html
BalusCa at 2007-7-8 8:44:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Check this:

<h:outputText value="Ward ID" />

<h:selectOneMenu id="wardId" value="#{WardController.id}" onchange="submit();" valueChangeListener="#{WardController.getBedValues}">

<f:selectItems value="#{WardController.wardList}" />

</h:selectOneMenu>

<h:outputText value="Bed ID" />

<h:selectOneMenu id="bedId" value="#{WardController.phone}" required="true">

<f:selectItems value="#{WardController.bedList}" />

</h:selectOneMenu>

my bean is like this :

public void getBedValues(){

try{

WardManagerDAO dao = new WardManagerDAO();

List allList = dao.showBeds(id);

bedList = new SelectItem[allList.size ()];

for(int i= 0;i<allList.size();i++){

WardDetail wards = (WardDetail)allList.get(i);

bedList=new SelectItem (wards.getBedId());

}

}

when i change the value of first list the following error occur:

javax.servlet.ServletException: getBedValues: com.obaidnoor.hms.controller.WardsController.getBedValues(javax.faces.event.ValueChangeEvent)

javax.faces.webapp.FacesServlet.service(FacesServlet.java:209)

With root cause :

javax.faces.el.MethodNotFoundException: getBedValues: com.obaidnoor.hms.controller.WardsController.getBedValues(javax.faces.event.ValueChangeEvent)

com.sun.faces.el.MethodBindingImpl.method(MethodBindingImpl.java:206)

com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:124)

javax.faces.component.UIInput.broadcast(UIInput.java:492)

javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:249)

javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:343)

com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:78)

com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)

com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)

javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)

It say that method not found . but i have this method in my bean.>

Atiqea at 2007-7-8 8:44:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

The error:javax.faces.el.MethodNotFoundException: getBedValues: com.obaidnoor.hms.controller.WardsController.getBedValues(javax.faces.event.ValueChangeEvent)

Your method:public void getBedValues(){

...

}

getBedValues(javax.faces.event.ValueChangeEvent) != getBedValues()

Please reread the errormessage and my code =)

BalusCa at 2007-7-8 8:44:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...