Reputation: 5667
Displaying Spring Dropdown in JSP if user does NOT have value in it.. I am trying to find out how to write some Spring code that will not display the following dropdown if the user has a value in the borough field coming back from the server?
<form:select path="borough">
<form:option value="Staten Island">Staten Island</form:option>
<form:option value="Queens">Queens</form:option>
<form:option value="Brooklyn">Brooklyn</form:option>
<form:option value="Bronx">Bronx</form:option>
<form:option value="Manhattan">Manhattan</form:option>
</form:select>
Upvotes: 0
Views: 1212
Reputation: 20323
You can use jstl conditional tag to get this done
<c:if test="${empty borough}">
<form:select path="borough">
<form:option value="Staten Island">Staten Island</form:option>
<form:option value="Queens">Queens</form:option>
<form:option value="Brooklyn">Brooklyn</form:option>
<form:option value="Bronx">Bronx</form:option>
<form:option value="Manhattan">Manhattan</form:option>
</form:select>
</c:if>
As per comment:
You can achieve if else by using c:choose
<c:choose>
<c:when test="${empty borough}">
<form:select path="borough">
<form:option value="Staten Island">Staten Island</form:option>
<form:option value="Queens">Queens</form:option>
<form:option value="Brooklyn">Brooklyn</form:option>
<form:option value="Bronx">Bronx</form:option>
<form:option value="Manhattan">Manhattan</form:option>
</form:select>
</c:when>
<c:otherwise>
This is the else block, you can have multiple when clause so it will become if else if else code
</c:otherwise>
</c:choose>
Some documentation
Upvotes: 2