Jsp 在Spring 3中将日历对象绑定到3个下拉框
我最近开始将我的网站移植到Spring3。我的模型有Author对象,我在其中存储了一些信息,其中包括Calendar类的一个对象 为了避免解析日期,我使用了3个下拉框来设置日历。在Spring2.5中,我使用onBind方法进行了翻译Jsp 在Spring 3中将日历对象绑定到3个下拉框,jsp,spring-mvc,spring-3,Jsp,Spring Mvc,Spring 3,我最近开始将我的网站移植到Spring3。我的模型有Author对象,我在其中存储了一些信息,其中包括Calendar类的一个对象 为了避免解析日期,我使用了3个下拉框来设置日历。在Spring2.5中,我使用onBind方法进行了翻译 @Override protected void onBind(HttpServletRequest request, Object command) throws Exception { Auteur auteur = (Auteur) command
@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将使用ServletRequestUtils返回日历对象。在我的JSP页面中使用:
<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>
我想知道如何将这段代码转换为Spring3,或者如果不可能,是否有其他替代方案。
感谢Spring 3中的@InitBinder可用于绑定对象
@InitBinder
protected void initBinder(WebDataBinder binder, WebRequest request) throws Exception {
//implementation
}
您可以使用WebRequest对象以同样的方式获取请求属性。有人能提供有关如何使用活页夹映射多个字段的信息吗?我只能找到@InitBinder用于1:1映射的示例。