Mehdi Bouzidi
Mehdi Bouzidi

Reputation: 1985

Primefaces Calendar Listener not affecting data to variable

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

Upvotes: 0

Views: 655

Answers (1)

mishh
mishh

Reputation: 123

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.

Upvotes: 1

Related Questions