Hi,
I'm converting an existing site from Cocoon 2.1 to Spring 2.5 MVC.
I have a form select element which appears at the top of every page to let a user change their location. How do I handle this form with Spring MVC?
At the moment I'm writing it without using Spring's form methods, but if there's a way to do this with them I'd try that.
I have a LocationList bean which I've inserted into every view, so I can iterate over it. Spring's EL syntax won't let me call methods, so the code I've got which adds the "selected" attribute doesn't work.
HTML Code:
<c:set var="currentLocation"><authz:authentication operation="locationKey"/></c:set>
<select name="locationKey" onchange="form.submit();">
<c:forEach var="location" items="${locationList.rootLocations}">
<c:choose>
<c:when test="${currentLocation == location}">
<option value="${location.key}" selected="selected">${location.name}</option>
</c:when>
<c:otherwise>
<option value="${location.key}">${location.name}</option>
</c:otherwise>
</c:choose>
</c:forEach>
</select>
The above code works fine and renders a drop-down list of locations, but it doesn't select the current location because of course you can't compare strings with ==. I can't call methods in JSTL so I can't use equals().
So what I want to know is:
- Should I be using Spring's form tags?
- If so, how? Bearing in mind this form appears on every page.
- Can I replace the expression language with something that can handle calling functions?