Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Getting One Dropdown Menu Selection to Affect the Values of a Second Dropdown Menu

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Esteemed Sirs et Madames,
I have 6 dropdown menus on the same Visual Web JSF page (Zone,Region,District,Facility,Year,Quarter). I need for it to be such that only when I make a zone selection should the region selection be populated with regions that are found within that particular zone selected in the zone dropdown menu. The same again with the district dropdown, it should only be populated once a region has been chosen so that the districts available for selection reflect the region.... and so on for the rest of the dropdowns. How can I go about this please?

Thanking you profusely in advance
 
Saloon Keeper
Posts: 21993
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use a JSF tagset that supports AJAX you can do this fairly easily. I've got an app that uses RichFaces to do exactly that kind of menu cascading.
 
Phoenix Kilimba
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks Tim, is there a way of using the current set up without getting into AJAX? AM using Visual Web JSF. Incidentally what would be the overhead of learning and using AJAX for this particular issue, and could I get your code for the cascading dropdown menus as a reference point?
Thanks
 
Tim Holloway
Saloon Keeper
Posts: 21993
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AJAX isn't required, but if you don't use AJAX, you have to reload the entire page each time you change one of the menus. The basic code is the same in either case - when a parent menu changes, you replace the datamodel for the child menu(s).

I haven't used NetBeans, and in any event, it's not the IDE that's got to work, it's the code.

Here's a snippet of some RichFaces JSF with AJAX-enabled cascading menus:


There isn't any AJAX code you have to write. The "a4j:support" tag manages the AJAX - it detects the "onchange" event on the menu and fires the valueChangeListeners in the backing bean. The ValueChangeListeners cause the datamodels for that menu's children to be reset. The reRender attributes limits the actual page updating to only those items named (matching "id" attributes) Otherwise the whole page gets refreshed.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the snippet that you post only works in session scope isnt it ?
will it work in request scope ? I try to get it to work with t:saveState yet it does not work.
 
Self destruct mode activated. Instructions for deactivation encoded in this tiny ad.
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic