You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Lau <hl...@gmail.com> on 2009/09/28 04:33:43 UTC

Using html:select with string arrays -> multiple options selected

When I am iterating through string arrays in my JSP, I am seeing the
resulting HTML having multiple options selected for one drop down box
instead of rendering multiple drop down boxes.

The JSP:
<logic:iterate name="SubForm" property="stockIds" id="stockId" indexId="i" >
                <tr >
                    <td width="10%">
                        <html:text name="SubForm" property="stockIds"
maxlength="10" size="10" value="${stockId}" />
                    </td>

                    <td width="10%">
                        <html:select name="SubForm" property="weight" >
                            <logic:notEmpty name="SubForm"
property="validWeights">
                                <html:optionsCollection name="SubForm"
property="validWeights" label="name" value="id" />
                            </logic:notEmpty>
                        </html:select>
                    </td>
                </tr >
</logic:iterate>

The rendered HTML for the drop down box would look like this if the array
for weight was {"1","2"}:

<select name="weight">
    <option value="1" selected="selected">One</option>
    <option value="2" selected="selected">Two</option>
    <option value="3">Three</option>
</select>

How can I make it so that it generates two select boxes with the first one
having "One" selected and the second one having "Two" selected?

Thanks in advance for your help!