Two Laptop Bag*
The moose likes JSF and the fly likes populate one dropdown options on change of another dropdown Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "populate one dropdown options on change of another dropdown" Watch "populate one dropdown options on change of another dropdown" New topic
Author

populate one dropdown options on change of another dropdown

Vallidevi Appana
Greenhorn

Joined: Jun 30, 2006
Posts: 25
Hi all,

I have two dropdowns in my jsp page. one dropdown is geographical unit and another dropdown is Country.
Whenever Geographical drop down changes, country dropdown should be populated again. I have used a4j:support to do this. But that Country dropdown is not repopulated. I don't want to use onchange="submit" attribute as it is creating problems.

This is my code in jsp page.



The code Service code is like this:



The countryList is populated properly on change of Geo Unit dropdown. But the Country dropdown is not rerendered.

Thank you very much in advance.

Regards
Valli
sivaji balla
Greenhorn

Joined: May 11, 2012
Posts: 7
Vallidevi Appana wrote:Hi all,

I have two dropdowns in my jsp page. one dropdown is geographical unit and another dropdown is Country.
Whenever Geographical drop down changes, country dropdown should be populated again. I have used a4j:support to do this. But that Country dropdown is not repopulated. I don't want to use onchange="submit" attribute as it is creating problems.

This is my code in jsp page.



The code Service code is like this:



The countryList is populated properly on change of Geo Unit dropdown. But the Country dropdown is not rerendered.

Thank you very much in advance.

Regards
Valli

hi,
I think you have to be call a method in <a4J:support> to populated the country values.
Then after, Just you just simply reRender the values in country drop down list.
May be it is useful to you.<a4j:support event="onchange" reRender="moons" value="{var.method()}"/>
Vallidevi Appana
Greenhorn

Joined: Jun 30, 2006
Posts: 25
Hi Sivaji,

Thank you very much for your response.
There is no value attribute availabe for a4j:support component.
Can you give me any more suggestions.

Regards
Valli
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

The ajaxSingle attribute causes the value of the first dropdown list to be set in the corresponding control property. Without it, the entire form would be submitted, and if any control on the form had an invalid value, the whole operation would be suppressed.

What I do to cascade dropdowns is to set the SelectItem list(s) on the dependent control(s) dynamically. That is, EntityMBean.getCountryList() contains logic like this:


I then pair that with a valueChangeListener attached to the GeoUnit control. It does this:


Because of the ordering of processes in the JSF lifecycle, this works out very neatly and has the side benefit that the same caching getCountryList method also works well when populating on initial form display.

Note that the valueChangeListener does not attempt to do major data operations itself - it just sets things up for when everything is neatly in place and ready to use.


Customer surveys are for companies who didn't pay proper attention to begin with.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Almost forgot. "entityMBean" is a very unfortunate name. "MBean" is conventionally used as the ending part of JMX MBean's classname, where "EntityMBean" would the the Management Bean classname for the "Entity" class. MBeans should not contain application logic. They are intended to manage the app, not to be the app.

"Entity" isn't a really happy name either, since in the case of JSF and JPA/EJB, use of Domain Model objects directly as backing beans doesn't usually work well, as the two types of model objects (Domain and View) have different scoping requirements in almost all cases.
Vallidevi Appana
Greenhorn

Joined: Jun 30, 2006
Posts: 25
Hi Tim,

Thank you very much for your response.
I have tried your solution and it is working fine as expected in FireFox browser.
But not working in IE9 explorer.
Could you suggest me any solution to make it work on IE 9 also.
Thank you very much in advance.

Regards
Valli
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

There's nothing in my approach that varies depending on the OS, Browser or versions, so I think you need to check and see if there's something in your copy of IE9 that's interfering with the proper functioning of AJAX. Also check the RichFaces configuration options in web.xml and make sure that your WEB-INF/lib directory only contains JSF implementation classes if and only if the webapp server requires them to be there. Tomcat does require those libraries, JEE full-stack servers do not and they will encounter conflicts between your webapp's JSF classes and the JSF classes that are part of the webapp server.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: populate one dropdown options on change of another dropdown