Hello,
I use PrimeFaces 6.2 with JSF 2.3 and found inconvenient that p:calendar uses java.util.Date as a binding value.
I think it would be better to support LocalDate and LocalDateTime instead.
Calendar support for LocalDate and LocalDateTime
I think it already might support it in some way?
https://github.com/primefaces/primefaces/issues/839
https://github.com/primefaces/primefaces/issues/990
https://github.com/primefaces/primefaces/issues/3072
https://github.com/primefaces/primefaces/issues/839
https://github.com/primefaces/primefaces/issues/990
https://github.com/primefaces/primefaces/issues/3072
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
-
- PrimeFaces Core Developer
- Posts: 3979
- Joined: 03 Dec 2010, 14:11
- Location: Bavaria, DE
- Contact:
You can easily add a converter. We will take care of it, to make it usable without converter, when PF swichtes to java8.
Thomas Andraschko
PrimeFaces | PrimeFaces Extensions
Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE
Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko
PrimeFaces | PrimeFaces Extensions
Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE
Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko
Converter code
html:
java:
For LocalDateTime the ToString-method is defined like this:
"Outputs this date-time as a String, such as 2007-12-03T10:15:30."
See https://docs.oracle.com/javase/8/docs/a ... eTime.html
kind regards
Lars
html:
Code: Select all
<p:calendar
converter="#{....calenderDateTimeConverter}"
converterMessage="..."
/>
Code: Select all
public Converter getCalenderDateTimeConverter() {
return new Converter() {
@Override
public Object getAsObject(
FacesContext context,
UIComponent component,
String value) {
return value;
}
@Override
public String getAsString(
FacesContext context,
UIComponent component,
Object value) {
return value.toString();
}
};
}
"Outputs this date-time as a String, such as 2007-12-03T10:15:30."
See https://docs.oracle.com/javase/8/docs/a ... eTime.html
kind regards
Lars
-
- PrimeFaces Core Developer
- Posts: 3979
- Joined: 03 Dec 2010, 14:11
- Location: Bavaria, DE
- Contact:
You can also add it globally with @FacesConvert and setting the type.
Thomas Andraschko
PrimeFaces | PrimeFaces Extensions
Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE
Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko
PrimeFaces | PrimeFaces Extensions
Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE
Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko
+1tandraschko wrote: ↑19 Mar 2018, 15:27You can also add it globally with @FacesConvert and setting the type.
-
- PrimeFaces Core Developer
- Posts: 3979
- Joined: 03 Dec 2010, 14:11
- Location: Bavaria, DE
- Contact:
Thats my converter
Code: Select all
@Named
@ApplicationScoped
@FacesConverter(forClass = LocalDate.class)
public class LocalDateTimeConverter implements Converter
{
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value)
{
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(extractPattern(component, context));
try
{
return LocalDate.parse(value, formatter);
}
catch (Exception e)
{
return null;
}
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value)
{
if (value == null || (value instanceof String && StringUtils.isBlank((String) value)))
{
return "";
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(extractPattern(component, context));
return formatter.format((LocalDate) value);
}
private String extractPattern(UIComponent component, FacesContext context)
{
// try to get infos from calendar component
if (component instanceof Calendar)
{
Calendar calendarComponent = (Calendar) component;
return calendarComponent.getPattern();
}
return null;
}
}
Thomas Andraschko
PrimeFaces | PrimeFaces Extensions
Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE
Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko
PrimeFaces | PrimeFaces Extensions
Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE
Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko
Its slated for 7.1 and no one has fixed it yet: https://github.com/primefaces/primefaces/issues/4646
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
-
- Information
-
Who is online
Users browsing this forum: No registered users and 39 guests