I have and entity user
which is receiving dates form a Struts 2 form using the jQuery plugin for datepicker
s 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?
Form excerpt:
<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>
Entity excerpt (dates are 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;
}
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.
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" />