Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LocalDate (only) with primefaces calendar

I want to display a primefaces calendar element with an associated LocalDate in the Bean.

I used How to use java.time.ZonedDateTime / LocalDateTime in p:calendar as an example. The example as is works fine, BUT I don't need the time part and more importantly I don't want the time part of the calendar to be displayed.

The problem is that when I change the pattern and remove the time part:

<p:calendar id="localDate"
        pattern="dd-MMM-yyyy"
        value="#{bean.periodFrom}">
    <f:converter converterId="localDateConverter" />
    <p:ajax update="display" />
</p:calendar>

the converter is no longer called/ used at all. Which surprises me a bit.

Removing the pattern does not work neither.

Is there an alternative way to use the example without the time part? And why is the converter no longer called when I "simplify" the pattern?

JSF 2.2/ Java8/ Primefaces 6

like image 340
morecore Avatar asked Nov 30 '25 13:11

morecore


1 Answers

The ajax update is not being triggered, because you didn't specify any event on which the update should be triggered.

If you do not specify any event, the default event type "change" will be used.

  • p:calendar triggers a "change" event, when you enter the date in the inputText and blur
  • p:calendar triggers a "dateSelect" event, when you select a date in the calendar popup

In your case, you should insert multiple event listeners:

<p:ajax update="display" />
<p:ajax event="dateSelect" update="display" />

So your code will result in:

<p:calendar id="localDate"
        pattern="dd-MMM-yyyy"
        value="#{bean.periodFrom}">
    <f:converter converterId="localDateConverter" />
    <p:ajax update="display" />
    <p:ajax event="dateSelect" update="display" />
</p:calendar>

(By the way: It is not possible to combine multiple events in the same p:ajax component as you can read here https://stackoverflow.com/a/38319944/1643015)

like image 133
Alexander Bering Avatar answered Dec 02 '25 04:12

Alexander Bering



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!