It seeems that the standard spring way to specify the selected item in an option menu (drop down list) is by looping through a list and checking each value for equality with a c:if statement (or using ternary ? operator), something like this:
<spring:bind path="tableInfo.table">
<select name="<c:out value="${status.expression}"/>">
<c:forEach items="${tableInfo.tables}" var="table">
<option value="<c:out value='${table}'/>"
<c:if test="${table eq tableInfo.table}">selected</c:if>>
<c:out value="${table}"/>
</option>
</c:forEach>
</select>
This compares poorly to the html:options tag provided with struts which can automatically deduce the selected item in the list. Is there any way to use html:options with a spring backed form? I couldn't get it to work, but it could look something like this:
<spring:bind path="tableInfo.table">
<html:select property="${tableInfo.table}">
<html:options collection="${tableInfo.tables}"/>
</html:select>
</spring:bind>
I guess the problem is that the html:options tag looks for a struts backed form to determine what is the current tableInfo.table value? Or maybe it's a namespace resolution conflict between struts and spring? It would be nice to be able to use the struts html tags to access spring variables, has anyone done this?


Reply With Quote