Multiple Values Form:Select in Spring Java

Have been searching how to do multiple values in Spring.

What is Spring?

Spring Java

There are no complications when displaying only a single id or a value while using spring and form taglib by doing this.

<form:select path=”prospect.wholeSaleId” items=”${List}”
itemLabel=”wholeSaleId” itemValue=”wholeSaleId”>

Now itemLabel would display the wholeSaleId value. The problem now is how to display let’s say wholeSaleId – CustomerName in the itemLabel. One workaround is to use the <c:forEach> core taglib.

<form:select path=”prospect.wholeSaleId”>
<c:forEach items=”${List}” var=”prospect”>
<form:option value=”${prospect.wholeSaleId}”><c:out value=”${prospect.wholeSaleId}”/> – <c:out value=”${prospect.companyName}”/></form:option>

Now by doing so, you are now able to display two value. The HTML equivalent of such will now display like this. (Assuming it has only 3 values)

<select name=”wholeSaleId”>
<option value=”wholeSaleIdValue1″>wholeSaleIdValue1 – companyName1</option>
<option value=”wholeSaleIdValue2″>wholeSaleIdValue2 – companyName2</option>
<option value=”wholeSaleIdValue3″>wholeSaleIdValue3 – companyName3</option>

So there you have it. A workaround for the form tag in Spring Framework.

Leave a Reply