Setting primefaces calendar end date after setting start date

假如想象 提交于 2019-12-02 16:21:45

问题


I'm using primefaces calendar for the creation of an event. With the "mindate" parameter i have disabled the days before the current day. I want to do this even with the end date, disabling the days before the start date. I don't know how to handle this, since the backing bean gets the start date only after the validation of the entire form.

I need the backing bean to be set right after entering the start date on the inputText field.

Here the HTML:

<p:calendar immediate="true" mindate="#{createEventBean.today}" id="startingtime" value="#{createEventBean.current.startingtime}"/>

<p:calendar mindate="#{createEventBean.current.startingtime}" id="endingtime" value="#{createEventBean.current.endingtime}"/>

here the backing bean's method:

public Date getToday(){
    return new Date();
}

回答1:


You can use <p:ajax> to update the end date on select of start date. The <p:calendar> supports the ajax event dateSelect which is fired when a date is selected.

So, this should do:

<p:calendar value="#{bean.startDate}" mindate="#{bean.today}">
    <p:ajax event="dateSelect" update="endDate" />
</p:calendar>
<p:calendar id="endDate" value="#{bean.endDate}" mindate="#{bean.startDate}" />


来源:https://stackoverflow.com/questions/28031729/setting-primefaces-calendar-end-date-after-setting-start-date

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