This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
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.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Oct 10, 2006
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?
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.