2
votes

I use PrimeFaces calendar component on page. Pattern attribute is set to MM/dd/yyyy HH:mm:ss. Component value attribute is linked to java.util.Date variable in bean. When i open the page date in format which i expect, but after change of the value, format will always change into different format.

Expected format - 06/15/2015 08:00:30

Format after change of value - 06/15/2015 8:00 AM

Component ussage.

<p:calendar value="#{someBean.someJava.UtilDateVariable}" pattern="MM/dd/yyyy HH:mm:ss" locale="en">
     <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss"/>
</p:calendar>

I already tried to check primefaces showcase and documentation, different locale specification and also usage of the localization script for current localization but with no effect.

Every suggestion is welcome.

2

2 Answers

2
votes

You do not need <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss"/>. This tag converts String to Object and viceversa.

The Primefaces documentation only uses the Pattern attribute and sometimes the locale attribute causes troubles. Try:

<p:calendar value="#{someBean.someJava.UtilDateVariable}" pattern="MM/dd/yyyy HH:mm:ss"/>
0
votes

I know this is old, but I had simalar problem, calendar showing right date, but when I opened the datepicker the pattern seemed to be wrong.

After three hours I ended it was bootstrap pattern.

To solve quickly I included a javascript file on the jsf page with setting for pattern:

In XHTML

<h:outputScript library="js" name="myscripts.js" />

IN JS

$(document).ready(function() {
    $.fn.datepicker.defaults.format = "dd/mm/yyyy";
});