You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Matthew Van Horn <ho...@accesstech.com> on 2003/05/15 09:50:11 UTC

using Arrays with html:select

OK, I'm new at this, and haven't had enough caffeine today.
It seems this should be a simple thing, but I can't make it work...

How do you use a String[] to populate an select/option list where the 
index of the array is the value and the string is the description?

Given:
public static final String[] THE_LIST = {"foo", "bar", "baz", "xyzzy", 
"plugh"};

How do I get:
<select name="theList">
	<option value="0">foo</option>
	<option value="1">bar</option>
	<option value="2">baz</option>
	<option value="3">xyzzy</option>
	<option value="4">plugh</option>
</select>

<html:select property="theList">
	<logic:iterate id="theItem" collection="Constants.THE_LIST" 
indexId="index">
		<html:option value="???"><bean:write name="theItem"/></html:option>
	</logic:iterate>
</html:select>

Follow-up:
How would I do it using a key into message resources (so I could have 
localized labels in the drop-down)


Thanks very much for clues,
Matt

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org