The moose likes Struts and the fly likes Need  help using 2 select lists in the same form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Need  help using 2 select lists in the same form" Watch "Need  help using 2 select lists in the same form" New topic

Need help using 2 select lists in the same form

Laura Matei

Joined: May 11, 2005
Posts: 1
Hello! I need some help. I have two dropdown lists on the same page. If I select an option in the first one I want the other one to change correspondingly.

For example: I have a list of event domains (culture, entertainment) and for each domain I have a list of categories (culture with theatre, opera,films and entertainment with parties, shows, concerts). I defined the event domain list in the class as an arrayList. I don't know how to define the lists for the event categories such that when choosing a domain in the form, automaticaly to display the corresponding categories. I give you the example for my first option list as I call it in the JSP:

<html:select name="workingEvntForm" property="event.chosenEventDomain>
<html ptions name="workingEventForm" property="eventDomains" />

in the

private static final List EVENT_DOMAIN_LIST = new ArrayList();
//private static final List EVENT_CATEGORY_LIST = new ArrayList();

/* Private Fields */

private Event event;
private List eventDomainList;

/* Static Initializer */

static {
/* Constructors */

public EventForm() {
this.event = new Event();
this.eventCityList = EVENT_CITY_LIST;
this.eventDomainList = EVENT_DOMAIN_LIST;
this.eventCategoryList= EVENT_CATEGORY_LIST;

/* JavaBeans Properties */

public Event getEvent() { return event; }
public void setEvent(Event event) { this.event = event; }
public List getEventDomains() { return eventDomainList; }


Please if you have an example it would help a lot! Thank you!
Nimchi Yung
Ranch Hand

Joined: Jan 27, 2004
Posts: 71
One approach is using Javascripts. Then you don't need to post the
request back to server when user clicks on any choice box.

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If when a user chooses an option in the first select box, the second select box can only be one of 2 or 3 different select boxes, I'd render all the possible select boxes with style="visibility:hidden" and then just use javaScript to display the correct one when the user makes a choice in the first select box.

However, if there are many possible choices for the second select box, I'd recommend submitting the form with the onchange event of the first select. Then have your action class format the proper select box for the second option and redisplay the page.

Consultant, Sima Solutions
I agree. Here's the link:
subject: Need help using 2 select lists in the same form
It's not a secret anymore!