Primefaces 5.1 calendar popup doesn't execute the valueChange event

半腔热情 提交于 2020-06-09 02:44:33

问题


I'm try to use the primefaces calendar with popup in this way:

<p:calendar pattern="yyyy-MMM-dd" value="#{controller.beginDate}" mask="true" navigator="true">
    <f:ajax event="valueChange" listener="#{controller.onChange}" />
</p:calendar>

And here is the relative controller:

@ManagedBean
public class Controller {
    private Date beginDate;

    public Date getBeginDate() {
        return beginDate;
    }

    public void setBeginDate(Date beginDate) {
        this.beginDate = beginDate;
    }

    public void onChange() {
        // do somethings
    }
}

The problem: if I change the value from the input field, the event will be execute, but if I change it from the popup, the event will NOT execute.

Can anyone help me?


回答1:


The valueChange event is only triggered by HTML DOM change event. This is indeed not triggered when the input value is manipulated by JavaScript means.

You need the dateSelect event instead. And, in PrimeFaces components, you'd better use <p:ajax> instead of <f:ajax>.

<p:calendar ...>
    <p:ajax event="valueChange" listener="#{controller.onChange()}" />
    <p:ajax event="dateSelect" listener="#{controller.onChange()}" />
</p:calendar>

See also:

  • PrimeFaces Users Guide



回答2:


Try using the PrimeFaces dateSelect event.

From PrimeFaces documentation:

Calendar provides a dateSelect ajax behavior event to execute an instant ajax selection whenever a date is selected. If you define a method as a listener, it will be invoked by passing an org.primefaces.event.SelectEvent instance.

<p:calendar value="#{calendarBean.date}">
    <p:ajax event="dateSelect" listener="#{bean.handleDateSelect}" />
</p:calendar>


来源:https://stackoverflow.com/questions/29370587/primefaces-5-1-calendar-popup-doesnt-execute-the-valuechange-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!