Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pre-populate Mulitple Select HTML Tag

 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ September 18, 2007: Message edited by: Erap Estrada ]
 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Merrill.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic