我对 f:convertDateTime 有问题,当我转换时间时,它似乎使用错误消息 javax.faces.converter.DateTimeConverter.DATE_detail (即它应该使用 javax.faces .converter.DateTimeConverter.TIME_detail)。
我猜问题是我使用了一种模式,因此它不知道它是要转换的日期还是时间。这就是我正在尝试的(“timePattern”是“hh.mm”):
<f:convertDateTime type="time" pattern="#{timePattern}" />
即使指定了 type="time",它仍然使用 DATE_detail 错误消息。这是一个错误还是我认为它应该使用错误消息TIME_detail错误,并且我必须创建自己的转换器?
最佳答案
不幸的是,DateTimeConverter
javadoc 也是如此。正在讲述。以下是相关性摘录:
If a
pattern
has been specified, its syntax must conform the rules specified byjava.text.SimpleDateFormat
. Such a pattern will be used to parse, and thetype
,dateStyle
, andtimeStyle
properties will be ignored.
但是我必须承认,JSF 男孩必须在 f:convertDateTime
pdldoc 中明确指定它。以及。从那里看并不明显。我会向 JSF 男孩报告问题,让他们澄清这部分。
要使其正常工作,最好的选择不是依赖模式,而是依赖 type
、dateStyle
和 timeStyle
(以及相反,或创建一个自定义日期时间转换器,扩展 DateTimeConverter
并相应地覆盖方法。
关于java - 使用 f 转换时间时出现日期错误 :convertDateTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3615458/