I am trying to add some code to my Spring JSP to display a list of boroughs if the user does not have one setup in the system.
Here is my JSP code:
<form:hidden path="borough" />
<c:choose>
<c:when test="${empty borough}">
<tr>
<td width="129"><span class="ast">*</span>Borough: </td>
<td width="361">
<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>
</td>
</tr>
</c:when>
<c:otherwise>
<form:hidden path="borough" />
</c:otherwise>
</c:choose>
The hidden field before the c:choose is for debugging only. Here is my output:
<input id="borough" name="borough" type="hidden" value="Queens"/>
<tr>
<td width="129"><span class="ast">*</span>Borough: </td>
<td width="361">
<select id="borough" name="borough">
<option value="Staten Island">Staten Island</option>
<option value="Queens" selected="selected">Queens</option>
<option value="Brooklyn">Brooklyn</option>
<option value="Bronx">Bronx</option>
<option value="Manhattan">Manhattan</option>
</select>
</td>
</tr>
So it looks like it thinks borough is always emply?
What is the “commandName” attribute in your
<form:form>? You will need to reference borough as a property of your command object. For example: