File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Pre-populate Mulitple Select HTML Tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Pre-populate Mulitple Select HTML Tag" Watch "Pre-populate Mulitple Select HTML Tag" New topic
Author

Pre-populate Mulitple Select HTML Tag

Erap Estrada
Ranch Hand

Joined: Nov 08, 2006
Posts: 92
How can I pre-populate Mulitple Select HTML Tag? For a tag with single value, I know that I can set it in my Action class through its custom form class.

How do I do it in multiple select?


SCJP with 98% by...
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You do it the same way as with a single select. Just populate the property associated with the html:select tag with some data and it will show as being selected in the JSP. The only difference is that for a multiple select,the property is a String array rather than just a single String, so you must populate one or more elements of the String array with data.


Merrill
Consultant, Sima Solutions
Erap Estrada
Ranch Hand

Joined: Nov 08, 2006
Posts: 92

[ September 18, 2007: Message edited by: Erap Estrada ]
Erap Estrada
Ranch Hand

Joined: Nov 08, 2006
Posts: 92
Well, I was wrong. To explain clearly my problem, I have 10 items on list, but only 3 of them should be selected.

If I set the values in my Form class, it will list only the 3 and not the whole. I should have 10 items with 3 selected.

Thanks in advance!
[ September 18, 2007: Message edited by: Erap Estrada ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
For any multiple-select box there are always two separate arrays or collections: one for the list of available options and another for the list of selected options. The list of available options is referenced by the htmlptions or htmlptionsCollection tag, and the list of selected options is referenced by the html:select tag. Your list of available options should contain the list of all possible options. Your list of selected options should be a subset of the available list and should contain only those options that should show as selected when the JSP is displayed.
Erap Estrada
Ranch Hand

Joined: Nov 08, 2006
Posts: 92
Thanks Merrill.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pre-populate Mulitple Select HTML Tag