<p:calendar and pattern problem

UI Components for JSF
Post Reply
msvahn
Posts: 2
Joined: 30 Jan 2010, 11:15

30 Jan 2010, 11:52

We are using the <p:calendar together with the pattern attribute and it does not format the date as we expects. The pattern yyyy-MM-dd is supposed to fill out the string with zeros for months and days less than 10 but it is not doing that. When you for instance select the first of january 2010 you get the string 2010-1-1 and we would like to have it formatted as 2010-01-01.

<p:calendar id="startDatePicker" value="#{bean.startDate}"
pattern="yyyy-MM-dd" startWeekday="1"
required="true"
timeZone="GMT"
>

Any ideas how to solve this or is it a bug in Primefaces?

We are using Primefaces 1.0.0.RC.

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

31 Jan 2010, 22:19

Hi,

I would recommend you to use an attached converter. I think, you can write your own converter and attach with f:converter. PrimeFaces uses java.text.SimpleDateFormat. I would not say that it's bad, but it's not good and flexible enough. We had to turn down SimpleDateFormat in our web-applications and are using JodaTime http://joda-time.sourceforge.net/. Since changing to JodaTime we are happy and don't have problems (format / parse) any more.

Best regards.
Oleg.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

msvahn
Posts: 2
Joined: 30 Jan 2010, 11:15

01 Feb 2010, 09:04

Hi,

Thanks for the answer but I think the problem is on the JavaScript side. We get the correct formatting after the form have been posted, it is just when you select the date in the calender that it uses the wrong formatting.

Best Regards
msvahn

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

01 Feb 2010, 11:06

Ok.

In my opinion, the JavaScript formatting / parsing is error-prone. I had headache with it. But it was in the past... In our web-apps we are offering now a selection of date / time patterns on the settings page. User can choose any pattern and it will be stored server-side in managed bean. So, if the user selects a date / time in the calendar an Ajax request is performed and a formatted date / time as string will come back and will be displayed in the calendar input field. I want to say that the proper formatting happens always on the server-side according to the selected by user date / time pattern.

- Oleg.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 44 guests