Tuesday, May 19, 2009

Spring mvc bind select

Here is an example to use spring:bind to bind HTML select. Note the hidden input at the end is very important to spring bind.


<spring:bind path="labelChanges.details">
<select id="detailFilter" name="${status.expression}" multiple="multiple" class="searchFilter">
<c:forEach var="item" items="${labelChangeMitigationDetails}">
<c:forEach items="${status.value}" var="currentItem">
<c:if test="${currentItem == item.value}">
<c:set var="selected" value="true"/>
</c:if>
</c:forEach>

<option value="${item.value}"
<c:if test="${selected}">selected="selected"</c:if>>
<c:out value="${item.key}" />
</option>

<c:remove var="selected"/>
</c:forEach>
</select>
</spring:bind>
<input type="hidden" name="_details" value="1"/>


Another options is to use form:select


<form:select id="statusFilter" cssClass="searchFilter"
path="statuses"
items="${labelChangeStatuses}"
itemValue="lcStatusRefSeq"
itemLabel="lcStatusName"
multiple="true" />
</td>

1 comment:

  1. can you provide the back bean architecture snippet also if it is possible?

    ReplyDelete