开发者

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_pane开发者_运维知识库l">
                  <f:ajax event="blur" execute="filledFromDate"
                     render="filledToDate_panel"></f:ajax>
 </p:calendar>


   public void test(DateSelectEvent event) {
       System.out.println("-------------->" + event);
    }
  • I want to implements this function: when I select the down-list of the Calendar , I want to invoke the test method right away, to put the select date to another Calendar input .

    If I don't add the converter . the method will be triggered.But after I add a converter , the method selectListener="#{searchMB.test}" can not be triggered.I don't konw why.Anyone can help me ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜