FishGel
FishGel

Reputation: 1110

Can not trigger the p:calendar's selectListener

My code is as follows :

<p:calendar showOn="button"
                  value="#{searchMB.filledFromDate}"
                  pattern="MM/dd/yyyy" maxlength="10" id="filledFromDate"
                  converter="submittedDateConverter"
                  converterMessage="#{message.filled_date_from_is_not_a_valid_date}"
                  styleClass="calendar" selectListener="#{searchMB.test}"
                  onchange="alert('')"
                  onSelectUpdate="filledToDate_panel">
                  <f:ajax event="blur" execute="filledFromDate"
                     render="filledToDate_panel"></f:ajax>
 </p:calendar>


   public void test(DateSelectEvent event) {
       System.out.println("-------------->" + event);
    }

Upvotes: 0

Views: 4267

Answers (1)

maple_shaft
maple_shaft

Reputation: 10463

You should not use the <f:ajax> tag within a Primefaces component.

For many Primefaces components you can use the <p:ajax> tag instead however for <p:calendar> you can instead use a variety of different attributes to give you Ajax functionality.

From the Primefaces Guide 2.2

OnSelectProcess - Components to process with ajax when a date is selected (default: @this).

And on Ajax selection listener from the guide:

Ajax Selection Calendar supports instant ajax selection which means whenever a date is selected a server side selectListener can be invoked with an org.primefaces.event.DateSelectEvent instance as a parameter. Optional onSelectUpdate option allows updating other component(s) on page.

<p:calendar value="#{calendarBean.date}" onSelectUpdate="messages"
     selectListener="#{calendarBean.handleDateSelect}" />
 <p:messages id="messages" />

Code behind

public void handleDateSelect(DateSelectEvent event) {
     Date date = event.getDate();
     //Add facesmessage
}

I am curious what you need the converter for anyway? The value attribute can be a managed bean property of the java.util.Date type without the need for an explicit converter.

Upvotes: 2

Related Questions