Struts 2 Jquery Datepicker格式问题 [英] Struts 2 Jquery Datepicker format issue
问题描述
我有一个实体 user
,它使用jQuery插件为日期选择器接收Struts2表单中的日期,并且每当我将日期格式从 mm/dd/yyy/
更改时设置为 mm/yyyy
,即使用户仍然必须默认选择日历的月/日/年,它也无法再正确设置日期.所以我的问题是,是否可以解决此问题,或者可以通过一种方法来更改将数据从表单传递到实体的方式来完成这项工作?
I have and entity user
which is receiving dates form a Struts2 form using the jQuery plugin for datepickers and whenever I change the date format from mm/dd/yyy/
to mm/yyyy
it no longer sets the date correctly anymore even though the user still has to select a month/day/year by default with the calendar. So my question is, is there a work around for this or a way to go about changing how the data is passed from the form to the entity to make this work?
表格摘录:
<tr>
<td style="border: 0px;">Contract Start-1</td>
<td style="border: 0px;">
<sj:datepicker name="user.nat_gas_start1" displayFormat="mm/dd/yy" yearRange="20011:2020" value="currentUser.nat_gas_start1"/>
</td>
</tr>
<tr>
<td style="border: 0px;">Month Shopping For-1</td>
<td style="border: 0px;">
<sj:datepicker name="user.nat_gas_end1" displayFormat="mm/yy" yearRange="20011:2020" value="currentUser.nat_gas_end1"/>
</td>
</tr>
实体摘录(日期为Java SQL):
public void setNat_gas_start3(Date nat_gas_start3) {
this.nat_gas_start3 = nat_gas_start3;
}
public Date getNat_gas_end1() {
return nat_gas_end1;
}
该窗体执行并执行操作,该操作将覆盖现有值并将其通过Hibernate传递到数据库中.直到我将结束日期格式切换为 mm/yyyy
格式之前,它一直有效.
The form executes and action which over writes the existing values and passes them into the database via Hibernate. It was previously working until I switched the end date format to the mm/yyyy
format.
推荐答案
您不应切换日期格式,日期格式'mm/yyyy'的处理不正确,因为错误的日期值会转换为操作.这些是正确的日期格式的示例:
You should not switch the date format, the date format 'mm/yyyy' is treated incorrectly, as a result wrong date value is converted to the action. These are examples of correct date formats:
<sj:datepicker value="today" id="date3" name="date3" displayFormat="dd.mm.yy" label="Today" />
<sj:datepicker value="yesterday" id="date4" name="date4" displayFormat="mm/dd/yy" label="Yesterday" />
<sj:datepicker value="tomorrow" id="date5" name="date5" displayFormat="DD, d MM yy" label="Tomorrow" />
<sj:datepicker value="2004-08-14" id="date6" name="date6" displayFormat="d M, yy" label="String Value" />
这篇关于Struts 2 Jquery Datepicker格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!