• 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

Dynamic content for drop downs

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In a struts project I have to create ONE web page with around 5-6 drop downs. The content of one drop down depends on the value selected in the previous one.

e.g

drop down 1 : UK (selected)
FRANCE

drop down 2 : LONDON
LEEDS

BUT if

drop down 1 : UK
FRANCE (selected)

drop down 2 : PARIS
NICE



Can any one tell me I can achieve this.

Thanks for the all the help in advance
Achal
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may want to check out the JSTL tags to see if any of them can help you do the logical things you need to do. A Struts-only solution for this doesn't exist obviously. Most of your work will depend on where the information comes from.
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use javascript if you don't mind creating the arrays of javascript objects in the page. the last array can be rather large if you have lots of data (you can find out how to do this by looking for some samples online).

you can also store DropDownItem[] in 1 array for each dropdown, each next DropDownItem[] would be like a data table containing a key to the previous one. store each DropDownItem[] in a session attribute (or you can put all 5 or 6 arrays of objects in 1 wrapper object). your struts Action class then do look ups (possibly using a helper method) against these arrays and return to the request ONLY collections of relevant dropdowns for use with your <html ptions> tags.

of course, you'll have to have some javascript that does a submit each time the user select a dropdown.

instead of using the action, you can also use JSTL to loop through each dropdown collection in your sessionScope, based on some parameter passing, (say /select.do?d1=1&d2=3&d3=&d4=&d5 that is constructed by javascript on each select) and display (using <c:if> or <logic:match> only the items for a particular selection. you'll need to add additional check to make sure the correct item is highlighted. complicated? yes, but doable. obviously, you'll need to go back to the server each time, but since the dropdowns are in session, it's not too bad...unless you have 1000's of user at any given time.
 
Achal Jalan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all your suggestions.

I would like to have all the information on the ONE webpage so that the action class doesn't need to called again n again. This seems possible only if all the data is already stored in 'javascript' variables.

I can get the information from the action class and display it onto the webpage, but how can I pass this information (arraylists consists of available options) into a 'javascript' function and initialize the variables?

Any help on this will be very very appreciated.

Thanks a bunch
Achal
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic