本文介绍了如果选择的日期早于特定日期,是否可以验证到rich:calendar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个组成部分:
<rich:calendar enableManualInput="true" value="#{home.born}" datePattern="dd/MM/yyyy" />
我需要验证所选日期是否等于或大于实际日期.只能使用rich:calendar来执行此操作吗?还是我必须将其验证到家中?
and i need to validate if the selected date is equal or before actual date at the momment...Is there how to do it only with rich:calendar or i must verify it into home?
问题解决了!我已经使用了Balusc提供的解决方案.谢谢大家! :)
Problem solved! i've used the solution provided by Balusc.Thanks everybody! :)
推荐答案
要在服务器端进行验证,可以使用Validator
.
To validate it on the server side, you can use a Validator
.
<rich:calendar ...>
<f:validator validatorId="notAfterToday" />
</rich:calendar>
使用
@FacesValidator("notAfterToday")
public class NotAfterTodayValidator implements Validator {
@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
Date date = (Date) value;
Date today = new Date();
if (date.after(today)) {
String message = "Date may not be later than today.";
throw new ValidatorException(new FacesMessage(message));
}
}
}
这篇关于如果选择的日期早于特定日期,是否可以验证到rich:calendar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!