This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Primefaces Calender component passing incorrect Date format  RSS feed

udaya krishna
Ranch Hand
Posts: 65
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am using the calender component of the primefaces and I am using the attribute .But when I print the values in my MBean along with the selected date event the timeZone (i think) is printed as I do not understand why its printed even though I have set the pattern.Part of my code :


Ok.I found out that we need to use <f:convertDateTimePattern> instead of how I am using currently.But I am not able to figure out where to use
in my case.
Udaya Krishna A
Tim Holloway
Posts: 18661
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You really shouldn't use System.out/System.err in webapps. They aren't defined for webapps and there's no telling where the output could go - including simply getting lost. A better approach is to use a logger.

The Date JSF extension controls are designed to interact with a Model object of type java.util.Date. You need a formatConverter (convertDateTime) if you want the JSF View to display/input a Date string that's not in the default form for your locale (the locale that the webapp server is running under).

However, the java.util.Date object itself is a binary class object. If you use it in an argument to System.out.print, the Date class toString() method is what converts the binary Date value to a displayable format.

The stock toString() method isn't designed for or expected to support alternate Date string formats. And it's completely independent of JSF. If you want precise control of how a Date gets converted to a string in backend code, you need to apply a DateFormatConverter to it. The DateFormatConverter classes are also what the JSF convertDateTime converter uses, but that's strictly on the Model/View/Controller side and doesn't carry into the business logic side.

One thing you should note, since it can bite you in web applications, and not just JSF web applications. Although Java provides 2 date classes (java.util.Date and java.sql.Date), these classes often don't match well to databases. In some databases, a "Date" is exactly that - just the date, and precise only to the day. Other databases may carry precision down to the second. Some to the microsecond. Often there's multiple date/time object types with differing precision levels. The java Date classes hold data precise to the millisecond, so when objects of these types are stored/loaded from a database, precision may be lost, values may not compare equal and key searches may fail.

In other words, when working with Date objects and databases, handle Dates the same way you'd handle floating-point numbers. Don't expect exact equality when comparing or searching.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!