I recently started porting my website to Spring 3. My model has Author objects in which I store some information which includes an object of the Calendar class.
To get rid of parsing dates I use 3 dropdown boxes for setting the Calendar. In Spring 2.5 I did the translation in the onBind method.
@Override
protected void onBind(HttpServletRequest request, Object command) throws Exception {
Auteur auteur = (Auteur) command;
Calendar geboorteDatum = getCompositeDate(request, "geboortedatum.time.date", "geboortedatum.time.month", "geboortedatum.time.year");
auteur.setGeboortedatum(geboorteDatum);
}
getCompositeDate would return the Calendar object using the ServletRequestUtils. With in my JSP page:
<form:select path="geboortedatum.time.date">
<c:forEach var="i" begin="1" end="31" step="1">
<form:option value="${i}" label="${i}" />
</c:forEach>
</form:select>
<form:select path="geboortedatum.time.month">
<c:forEach var="i" begin="1" end="12" step="1">
<form:option value="${i - 1}" label="${i}" />
</c:forEach>
</form:select>
<form:select path="geboortedatum.time.year">
<c:forEach var="i" begin="1900" end="2013" step="1">
<form:option value="${i}" label="${i}" />
</c:forEach>
</form:select>
I wonder how it would be possible to convert this code to Spring 3, or if there are alternatives if not possible. Thanks
In Spring 3 @InitBinder can be used to bind an object
@InitBinder
protected void initBinder(WebDataBinder binder, WebRequest request) throws Exception {
//implementation
}
You can get request attributes in the same way by using the WebRequest object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With