File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help using 2 select lists in the same form

 
Laura Matei
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 EventForm.java 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" />
</html:select>

in the EventForm.java

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 {
EVENT_DOMAIN_LIST.add("CULTURE");
EVENT_DOMAIN_LIST.add("ENTERTAINMENT");
EVENT_DOMAIN_LIST.add("SPORT");
EVENT_DOMAIN_LIST.add("COMERCE");
}
/* 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!
Laura
 
Nimchi Yung
Ranch Hand
Posts: 71
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One approach is using Javascripts. Then you don't need to post the
request back to server when user clicks on any choice box.

--Nimchi
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic