Jsf PrimeFaces日历范围
我使用PrimeFaces日历表示日期范围(为此,我使用两个日历)。Jsf PrimeFaces日历范围,jsf,primefaces,Jsf,Primefaces,我使用PrimeFaces日历表示日期范围(为此,我使用两个日历)。 如何在运行时更改日期范围,以便第一个日历范围小于或等于第二个日历值。例如,时间范围:您只需要将p:ajax与dateSelect事件一起使用,并在ManageBean方法中更新第二个日历的最小日期范围 例如:- <p:calendar id="fromDate" value="#{calendarView.fromDate}"> <p:ajax event="dateSelect" l
如何在运行时更改日期范围,以便第一个日历范围小于或等于第二个日历值。例如,时间范围:您只需要将p:ajax与dateSelect事件一起使用,并在ManageBean方法中更新第二个日历的最小日期范围 例如:-
<p:calendar id="fromDate" value="#{calendarView.fromDate}">
<p:ajax event="dateSelect" listener="#{calendarView.onDateSelect}" update="toDate" />
</p:calendar>
<p:calendar id="toDate" value="#{calendarView.toDate}" mindate="#{calendarView.toDateMin}"/>
希望这对您有所帮助:)除了前面的答案之外: 这将做得很好,但不是一个完整的,仍然当您手动编辑它时,您可以通过,并且范围将为false。 要实现这一点,您需要实现一个定制的JSF日期验证器
@FacesValidator("primeDateRangeValidator")
public class PrimeDateRangeValidator implements Validator {
@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
if (value == null) {
return;
}
//Leave the null handling of startDate to required="true"
Object startDateValue = component.getAttributes().get("fromDate");
if (startDateValue==null) {
return;
}
Date startDate = (Date)startDateValue;
Date endDate = (Date)value;
if (endDate.before(startDate)) {
throw new ValidatorException(
FacesMessageUtil.newBundledFacesMessage(FacesMessage.SEVERITY_ERROR, "", "msg.dateRange", ((Calendar)component).getLabel(), startDate));
}
}
}
并将其添加到您的日历中
<f:validator validatorId="primeDateRangeValidator" />
可能是重复的谢谢,这对我很有用。我很乐意帮助您。我想答案一定是P