Chris
Chris

Reputation: 4648

Primefaces Calendar with Converter doesn't update correctly upon ajax "valueChange" event

I want my p:calendar to work both by clicking on a date in the calendar popup, as well as by editing the date directly in the text input field.

This works fine:

        <p:calendar value="#{myBackingBean.date}">
            <p:ajax event="valueChange" listener="#{myBackingBean.updateDate()}" />
            <p:ajax event="dateSelect" listener="#{myBackingBean.selectDate()}" />
        </p:calendar>

However, as soon as I add a converter (see below), the new date is no longer set for "valueChange" events (when the date is edited by keyboard in the text field), even though the new date is converted correctly, but the date that is set in the backing bean is the old value, not the new one I edited in the text field:

        <p:calendar value="#{myBackingBean.date}">
            <f:converter converterId="myLocalDateConverter"/>
            <p:ajax event="valueChange" listener="#{myBackingBean.updateDate()}" />
            <p:ajax event="dateSelect" listener="#{myBackingBean.selectDate()}" />
        </p:calendar>

How can I get this to work together?

Upvotes: 0

Views: 1214

Answers (2)

Chris
Chris

Reputation: 4648

I found the cause of the problem: The converter was receiving text from the input field that it wasn't able to correctly convert. Apparently this leads to an interruption of the standard JSF lifecycle and the old value is set instead of the new one. With properly formatted input the whole thing works as expected.

Upvotes: 0

Sumit Gulati
Sumit Gulati

Reputation: 675

Refer this. https://www.javacodegeeks.com/2015/06/utilizing-the-java-8-date-time-api-with-jsf-and-java-ee-7.html

Its is using converter attribute of Calendar to implement the custom converter. This example is specifically for Java 8 Date API. You can write your code accordingly.

Upvotes: 1

Related Questions