File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Multiple selections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Multiple selections" Watch "Multiple selections" New topic

Multiple selections

Chris Boldon
Ranch Hand

Joined: Aug 10, 2006
Posts: 190
I'm trying to use a select box, with multiple selections.

I originally had the input types on my form all set to String. With this it would only give me the first item selected from the box. I assumed this was because the tag returns a String[]. When I change the form to accept a String[] it errors out. Can anyone please point me to an example using this, or an explaination. Thank you.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
String[] is the correct type to use with an <html:select> tag that allows multiple selection. Make sure that both your getter and setter use this type. Also make sure that it is not null. You should declare it something like this:

private String[] mySelect = new String[0];

or else put the following statement in your reset() method:

myselect = new String[0];

If you've tried these suggestions and it still doesn't work, please tell us the error message you're getting and post relevant portions of the jsp and struts-config.xml file.

Consultant, Sima Solutions
Chris Boldon
Ranch Hand

Joined: Aug 10, 2006
Posts: 190
When I add a project, via my add form it only adds the first item in the list, not any selected items following. When I use the edit form it resets the field to null, no matter what is selected. Code snippets follow.

Add Form:


-getters and setters

Add Action:

Edit Form:

Edit Action:

Value Object (ProjectImpl):


[ September 12, 2006: Message edited by: Chris Novindus ]
I agree. Here's the link:
subject: Multiple selections
It's not a secret anymore!