最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jsf - How to disallow invalid LocalDate in f:convertDateTime? - Stack Overflow

programmeradmin1浏览0评论

I'm using JSF Mojarra 2.3.17 and JRE 21. My bean has a LocalDate variable and the following JSF page:

<h:inputText value="#{bean.date1flt}" pt:type="date">
  <f:convertDateTime type="localDate" pattern="yyyy-MM-dd" />
</h:inputText>

Why does it not have some sort of error message for "2024-06-31" when it's not a valid date (30 days in June). Instead, it sets the bean variable to null. If I try LocalDate.of(2024, 6, 31); I get java.time.DateTimeException: Invalid date 'JUNE 31', which is good, but nothing if I use JSF.

I'm using JSF Mojarra 2.3.17 and JRE 21. My bean has a LocalDate variable and the following JSF page:

<h:inputText value="#{bean.date1flt}" pt:type="date">
  <f:convertDateTime type="localDate" pattern="yyyy-MM-dd" />
</h:inputText>

Why does it not have some sort of error message for "2024-06-31" when it's not a valid date (30 days in June). Instead, it sets the bean variable to null. If I try LocalDate.of(2024, 6, 31); I get java.time.DateTimeException: Invalid date 'JUNE 31', which is good, but nothing if I use JSF.

Share Improve this question edited Jan 18 at 20:50 BalusC 1.1m376 gold badges3.6k silver badges3.6k bronze badges asked Dec 15, 2024 at 11:10 EdwardEdward 6244 silver badges19 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

It should indeed have used non-lenient parsing. This is also specifically requested in the spec:

In all cases, parsing must be non-lenient; the given string must strictly adhere to the parsing format.

This worked for java.util.Date but not for its java.time.* cousins. That's thus a bug in Mojarra. I fixed it for Mojarra 4.0.10.

In the meanwhile, your best bet is to use a custom converter.

发布评论

评论列表(0)

  1. 暂无评论