Calendar support for LocalDate and LocalDateTime

UI Components for JSF
vished
Posts: 479
Joined: 02 Feb 2014, 17:38

09 Apr 2019, 19:28

Oh, ok.... but the code from tandraschko is not working for me...

extractPattern() is causing the issue... I cannot cast etc.?
PF 8.0

vished
Posts: 479
Joined: 02 Feb 2014, 17:38

09 Apr 2019, 20:15

Melloware wrote:
09 Apr 2019, 19:22
Its slated for 7.1 and no one has fixed it yet: https://github.com/primefaces/primefaces/issues/4646
when can this be integrated? I´ve changed my whole project now to LocalTime / LocalDateTime. I thought it´s already there....
PF 8.0

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

09 Apr 2019, 20:16

Not until 7.1 because it requires Java 8. PF 7.0 was still Java7 and PF7.1 will be the first version to switch to Java 8.
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

vished
Posts: 479
Joined: 02 Feb 2014, 17:38

09 Apr 2019, 20:19

Oh no :-/

1) How long will it take for 7.1 ?
2) Can you please let me know a workaround for it?
PF 8.0

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

09 Apr 2019, 20:24

7.1 most like not until the EOY 2019.

As for your issue. keep googling and stack overflowing, that you are trying to do definitely works...
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

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

10 Apr 2019, 08:39

A converter works fine - no idea why my converter it doesn't work in your application. It works fine for me.
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

erickdeoliveiraleal
Posts: 79
Joined: 25 Mar 2013, 13:00

17 Apr 2019, 17:42

tandraschko wrote:
20 Mar 2018, 10:56
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;
    }
}
You shared the converter for localdate but the class name is LocalDateTimeConverter, can you post also the LocalDateTime converter?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 48 guests