Calendar: LocalDateTime validation too lenient
See original GitHub issueValidation of java.util.Date
is more strict than the validation of LocalDateTime
. Example see below. Before PrimeFaces 8 I was using a custom Converter which sets DateTimeFormatter
to ResolverStyle.STRICT
. This would lead to the same behavior for LocalDateTime
as for java.util.Date
.
I think BaseCalendarRenderer:convertToJava8DateTimeAPI
should be updated to use ResolverStyle.STRICT
in the DateTimeFormatter
as this is consistent to java.util.Date
parsing. Currently, by default ResolverStyle.SMART is used.
Another way would be to add a new attribute to p:calendar
and companions to let the user select the ResolverStyle. What do you think?
Is there any chance to get this into 8.0.Final if I submit a PR? 😬
Just for reference: I was discussing this already in the forum: PrimeFaces 8.0.RC2, p calendar: ResolverStyle.STRICT.
1) Environment
- PrimeFaces version: 8.0.RC2
2) Expected behavior
When parsing a java.util.Date
I get an validation error, if I enter 30.02.2020 00:00:00
:
The same error should popup for
LocalDateTime
.
3) Actual behavior
The same date when validated to a LocalDateTime
gets parsed but gets quietly adjusted:
A date of
32.02.2020 00:00:00
will popup the validation message 😩
4) Steps to reproduce
Enter the date: 30.02.2020 00:00:00 Example here: https://github.com/kaiwinter/primefaces-test
5) Sample XHTML
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>PrimeFaces Test</title>
</h:head>
<h:body>
<h:form id="form">
<p:growl id="msgs" showDetail="true" skipDetailIfEqualsSummary="true" />
<h:panelGrid columns="4">
<p:outputLabel for="button1" value="Date:" />
<p:calendar
id="button1"
value="#{testView.date}"
showOn="button"
pattern="dd.MM.yyyy HH:mm:ss"
navigator="true"/>
<p:outputLabel for="button1Result" value="Parsed:" />
<p:outputLabel id="button1Result" value="#{testView.date}" />
<p:outputLabel for="button2" value="LocalDateTime:" />
<p:calendar
id="button2"
value="#{testView.localDateTime}"
showOn="button"
pattern="dd.MM.yyyy HH:mm:ss"
navigator="true"/>
<p:outputLabel for="button2Result" value="Parsed:" />
<p:outputLabel id="button2Result" value="#{testView.localDateTime}" />
</h:panelGrid>
<p:commandButton value="Submit" update="msgs button1Result button2Result" />
</h:form>
</h:body>
</html>
6) Sample bean
@Named
@ViewScoped
public class TestView implements Serializable {
private Date date;
private LocalDateTime localDateTime;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public LocalDateTime getLocalDateTime() {
return localDateTime;
}
public void setLocalDateTime(LocalDateTime localDateTime) {
this.localDateTime = localDateTime;
}
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
We should make this configureable via a new ResolverStyle-attribute. (IMO it depends on the usecase what´s “right”.) And we should do this for Calendar and DatePicker. PR is welcome. (Please also add a few UnitTest´s for this.)
Great, I’ve opened a new PR. Sorry for the inconvenience and thanks for your fast replies that makes it a pleasure to contribute here.