在设置开始日期后设置 primefaces 日历结束日期 [英] Setting primefaces calendar end date after setting start date
问题描述
我正在使用 primefaces 日历来创建活动.使用mindate"参数,我禁用了当天之前的几天.即使结束日期,我也想这样做,禁用开始日期之前的几天.我不知道如何处理这个问题,因为支持 bean 仅在整个表单验证后才获得开始日期.
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.
我需要在 inputText 字段中输入开始日期后立即设置支持 bean.
I need the backing bean to be set right after entering the start date on the inputText field.
这里是 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}"/>
这里是支持 bean 的方法:
here the backing bean's method:
public Date getToday(){
return new Date();
}
推荐答案
您可以使用 <p:ajax>
在选择开始日期时更新结束日期.<p:calendar>
支持在选择日期时触发的 ajax 事件 dateSelect
.
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.
所以,应该这样做:
<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}" />
这篇关于在设置开始日期后设置 primefaces 日历结束日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!