Value Change listener not working in primefaces calendar

mrugeshthaker picture mrugeshthaker · Dec 31, 2012 · Viewed 56.7k times · Source

I am using primefaces 3.2 and JSF 2.0

My scenario is I have file date, last date and next date in my form. When user enters file date I need to update file date value in bean so it's value can be used as minimum date in last date of attribute mindate and so in next date selection.

As per my knowledge value change listener can execute at form submission so I can not use it. I have used p:ajax. But still I am not able to set file date. As file date is not set it allows user to select last date and next date before date of file date.

caseMaster.xhtml

<p:calendar value="#{caseUitility.caseMaster.fileDate}" id="fileDate" effect="fadeIn" pattern="dd/MM/yyyy" readOnlyInputText="true">
    <p:ajax event="change" listener="#{caseUitility.dateChange}"/>
</p:calendar>

<p:calendar value="#{caseUitility.caseMaster.lastDate}" required="true" id="lastDate" effect="fadeIn" pattern="dd/MM/yyyy" readOnlyInputText="true" mindate="#{caseUitility.caseMaster.fileDate}" >
</p:calendar>

CaseUitility.java

public void dateChange(ActionEvent ae) {
    System.out.println("File Date: " + caseMaster.getFileDate());
    System.out.println("Hello... I am in DateChange");
}

can any guide me what am I doing wrong here?

Answer

Daniel picture Daniel · Dec 31, 2012

In more recent versions of PrimeFaces, SelectEvent should be usedsee the following code snippet

<p:calendar id="event" value="#{calendarView.date4}">
    <p:ajax event="dateSelect" listener="#{calendarView.onDateSelect}" update="msgs" />
</p:calendar>
public void onDateSelect(SelectEvent event) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
    facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Date Selected", format.format(event.getObject())));
}

In older primefaces versions use DateSelectEvent