在 dropdownDatePicker 中,您有 ${path} (在您的示例中为“someDateFieldInFormBean”)。使用访问器和修改器使用年、月和日字段扩展它的类型,然后在 dropdownDatePicker-tag 中,将字段的路径设置为 ${path}.year、${path}.month 和 ${path}.day
例如:控制器:
@RequestMapping(value = BASE_URL + "/test", produces = TEXT_HTML) public String test(final Model uiModel) {
Formstuff formstuff = new Formstuff();
DatePicker datePicker = new DatePicker();
datePicker.setYear(1234L);
datePicker.setMonth(2345L);
datePicker.setDay(3456L);
formstuff.setDatePicker(datePicker);
uiModel.addAttribute("formstuff", formstuff);
return "test";
}
表格类:
class Formstuff {
private DatePicker datePicker;
public DatePicker getDatePicker() {
return datePicker;
}
public void setDatePicker(final DatePicker datePicker) {
this.datePicker = datePicker;
}
@Override
public String toString() {
return "Formstuff [datePicker=" + datePicker + "]";
}
}
日期选择器类:
public class DatePicker {
private Long year;
private Long month;
private Long day;
public Long getYear() {
return year;
}
public void setYear(final Long year) {
this.year = year;
}
public Long getMonth() {
return month;
}
public void setMonth(final Long month) {
this.month = month;
}
public Long getDay() {
return day;
}
public void setDay(final Long day) {
this.day = day;
}
@Override
public String toString() {
return "DatePicker [year=" + year + ", month=" + month + ", day=" + day + "]";
}
}
相关jsp:
<jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:util="urn:jsptagdir:/WEB-INF/tags/util"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:form="http://www.springframework.org/tags/form" version="2.0">
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<jsp:output omit-xml-declaration="yes" />
<util:pageBody title="Datepicker test page" >
<form:form commandName="formstuff">
<util:datepicker name="example" yearsBack="10" path="datePicker"/>
</form:form>
</util:pageBody>
</jsp:root>
和标签:
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:spring="http://www.springframework.org/tags"
xmlns:form="http://www.springframework.org/tags/form" version="2.0">
<jsp:directive.attribute name="name" type="java.lang.String"
description="" />
<jsp:directive.attribute name="path" type="java.lang.String"
description="" />
<jsp:directive.attribute name="yearsBack" type="java.lang.Long"
description="" />
<jsp:output omit-xml-declaration="yes" />
<h1>${name}</h1>
<h1>${path}</h1>
<h1>${yearsBack}</h1>
<form:input path="${path}.year" />
<form:input path="${path}.month" />
<form:input path="${path}.day" />
<input type="submit"/>
</jsp:root>
我希望,我的回答是有帮助的。