我有这个组件:
<rich:calendar enableManualInput="true" value="#{home.born}" datePattern="dd/MM/yyyy" />
Run Code Online (Sandbox Code Playgroud)
我需要验证选定的日期是否相等,或者在实际日期之前验证...是否只有富人才能做到:日历或我必须验证它到家里?
问题解决了!我使用了Balusc提供的解决方案.谢谢大家!:)
Bal*_*usC 10
要在服务器端验证它,您可以使用Validator.
<rich:calendar ...>
<f:validator validatorId="notAfterToday" />
</rich:calendar>
Run Code Online (Sandbox Code Playgroud)
同
@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));
}
}
}
Run Code Online (Sandbox Code Playgroud)