Reputation: 92
I have a datepicker object on my page, it works fine, but when I handle it in my ManagedBean class, with java util date variable, it returns wrong month of the year, and sometimes with one day different.
There is my datepicker object:
$(".datepicker").datepicker({
dateFormat: 'yy-mm-dd' ,
changeMonth: true,
changeYear: true,
yearRange: "-70:+0"
});
my xhtml:
<h:inputText styleClass="datepicker"
value="#{registerManagedBean.dateOfBirth}">
<f:convertDateTime pattern="yyyy-mm-dd" />
</h:inputText>
I call my ManagedBean class register method, for the form submit:
public void Registration() {
System.out.println("Registration: " + firstName + ", " + surName + ", "
+ dateOfBirth);
playerSessionBean.addPlayer(new Player(dateOfBirth, email, firstName,
height, surName, team, weight));
}
Some example input output:
Selected value: 2014.10.06 ==> Output: 2014.01.05
Selected value: 2013.07.10 ==> Output: 2013.01.09
Selected value: 2014.03.26 ==> Output: 2014.03.25
Upvotes: 1
Views: 890
Reputation: 17971
Looking at your <f:dateTimeConverter />
pattern:
<f:convertDateTime pattern="yyyy-mm-dd" />
Unlike date picker widget, here mm
refers to minutes not months. It should be:
<f:convertDateTime pattern="yyyy-MM-dd" />
See f:convertDateTime tag reference
Upvotes: 3