views:

99

answers:

2

Hi,

I have problem with f:convertDateTime, that it seems to use the error message *javax.faces.converter.DateTimeConverter.DATE_detail* when I convert time (i.e. it should use *javax.faces.converter.DateTimeConverter.TIME_detail*).

The issue, I'm guessing, is that I use a pattern, and thus it does not know if it's a date or a time that it is tying to convert. This is what I'm trying ("timePattern" is "hh.mm"):

<f:convertDateTime type="time" pattern="#{timePattern}" />

Even though type="time" is specified, it still uses the *DATE_detail* error message. Is this an bug or is my assumption that it should use the *TIME_detail* error message wrong, and I have to create my own converter?

A: 

You have also to define javax.faces.converter.DateTimeConverter.TIME in your messages.

Look here: http://www.icefaces.org/JForum/posts/list/16119.page One post before last one.

amorfis
It is defined, and f:convertDateTime uses that if it is used with type="time" and *no* pattern. The problem here is that the DATE error message is used, when type="time" *and* pattern="whatever" is used.
vetler
+2  A: 

Unfortunately, that's also what the DateTimeConverter javadoc is telling. Here's an extract of relevance:

If a pattern has been specified, its syntax must conform the rules specified by java.text.SimpleDateFormat. Such a pattern will be used to parse, and the type, dateStyle, and timeStyle properties will be ignored.

I must however admit that the JSF boys had to specify it explicitly in the f:convertDateTime pdldoc as well. It's not obvious from there. I'd report an issue to the JSF boys to get them to clarify this part.

To get it to work, your best bet is either not relying on the pattern, but on type, dateStyle and timeStyle (and the locale) instead, or create a custom date time converter which extends DateTimeConverter and overrides the methods accordingly.

BalusC
Thanks, good answer! I ended up creating a converter, but was hoping to avoid it.
vetler