You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Caroline Jen <ji...@yahoo.com> on 2004/09/14 15:47:04 UTC

The Tag and Drop Down Menu

To make it simple, there is a JavaBean.  This JavaBean
has two properties: label and value.  Because I have a
number of label and value pairs, I have a Collection
of this JavaBean(s).

To create a drop down menu, I do the following:

<bean:define id="GiveAnyName"
name="NameOfTheCollectionOfJavaBeans" scope="request"
type="java.util.ArrayList"  />

<html:select size="1" property="Property in the form
bean to hold the selection" multiple="false">
    <html:options
collection="NameOfTheCollectionOfJavaBeans"
property="value"
labelProperty="label"/>
</html:select>

How do I use the <c:...  > tag to do the same thing?


		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 

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


Re: The Tag and Drop Down Menu

Posted by Jason Lea <ja...@kumachan.net.nz>.
Something like this in JSP1.2:
assuming the Struts form bean is called 'formbean' and the property is 
called 'property'

<select size="1" name="property" multiple="false">
    <c:forEach items='${NameOfTheCollectionOfJavaBeans}' var='item'>
        <option value="<c:out value='${item.value}'>" <c:if test="${item.value==formbean.property}">selected</c:if>><c:out value='${item.label}'></option>
    </c:forEach>
</select>


or in JSP2.0:

<select size="1" name="property" multiple="false">
    <c:forEach items="${NameOfTheCollectionOfJavaBeans}" var="item">
        <option value="${item.value}" ${item.value==formbean.property ? "selected" : }>${item.label}</option>
    </c:forEach>
</select>



Caroline Jen wrote:

>To make it simple, there is a JavaBean.  This JavaBean
>has two properties: label and value.  Because I have a
>number of label and value pairs, I have a Collection
>of this JavaBean(s).
>
>To create a drop down menu, I do the following:
>
><bean:define id="GiveAnyName"
>name="NameOfTheCollectionOfJavaBeans" scope="request"
>type="java.util.ArrayList"  />
>
><html:select size="1" property="Property in the form
>bean to hold the selection" multiple="false">
>    <html:options
>collection="NameOfTheCollectionOfJavaBeans"
>property="value"
>labelProperty="label"/>
></html:select>
>
>How do I use the <c:...  > tag to do the same thing?
>
>
>		
>__________________________________
>Do you Yahoo!?
>New and Improved Yahoo! Mail - Send 10MB messages!
>http://promotions.yahoo.com/new_mail 
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>  
>


-- 
Jason Lea



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