0

I have two Datepicker/Calendar(Primefaces) , what I want to do is when I'll click on the second Calendar I'll call a Listener that will caclulate the days between the two dates. So this is what I've did:

Web Page

<a:column span="4" >
            <a:label value="Begining Date" span="4"   required="true"  ></a:label>
            <a:column span="8">
                <p:calendar  id="idBegDate"  value="#{addController.enti.begDate}"
                             pattern="dd/MM/yyyy"  label="Begining Date" 
                             readonlyInput="true" locale="fr" navigator="true"
                             required="true" >

                </p:calendar>

            </a:column>
        </a:column>

        <a:column span="4" >
            <a:label value="End Date" span="4"   required="true"  ></a:label>
            <a:column span="8">
                <p:calendar  id="idDateFin"  value="#{addController.enti.dateFinAbsAgt}"
                             pattern="dd/MM/yyyy"  label="End Date" 
                             readonlyInput="true" locale="fr" navigator="true"
                             required="true" >
                    <p:ajax event="dateSelect" listener="#{addController.doCalculate()}" update="jourCalendaire" />
                </p:calendar>

            </a:column>
        </a:column>

Backing Bean

public void doCalculate()
{
//..Some Stuffs
}

The problem is that when the listener is called it says that the dateOfBegining is NULL while it shouldn't be.

I found the solution to this issue by adding an empty listener to the first calendar:

public void emptyListener()
{

}

I think this is not logical, so I want to know why the webpage/backingBean had this behavior ? Is there a way in which I can use only the listener of the second calendar ?

Thanks

Mehdi Bouzidi
  • 1,937
  • 3
  • 15
  • 31
  • 1
    Possible duplicate of [Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes](https://stackoverflow.com/questions/25339056/understanding-primefaces-process-update-and-jsf-fajax-execute-render-attributes) – Kukeltje Dec 21 '17 at 15:17

1 Answers1

1

On the p:ajax of the second calendar, you need to add process="@this idBegDate" so JSF knows to take the value of @this (the second calendar) and idBegDate (the first calendar) and put it into your model object.

Nothing from the view will come back to the server unless you process it. Adding a p:ajax to the first calendar processed it for you.

Mitchell Brooks
  • 113
  • 2
  • 9
  • This is working, can you please explain me why It doesn't affect it to the `backingbean` variable when I don't have `` in the first date ? – Mehdi Bouzidi Dec 24 '17 at 10:41
  • @MehdiBouzidi read [process/update attributes](https://stackoverflow.com/questions/25339056/understanding-primefaces-process-update-and-jsf-fajax-execute-render-attributes). My short version is `process` attribute tells JSF what to _process_ from the view and updates the bean values bound to those components – Mitchell Brooks Dec 25 '17 at 19:49