• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic