我有一个实现Validator的类,所以我可以为属性定义一些自定义验证规则:
@Override
public void validate(FacesContext fc, UIComponent uic, Object obj) throws ValidatorException {
Date date = (Date)obj;
if(date == null) {
FacesMessage msg = new FacesMessage("no value");
throw new ValidatorException(msg);
}
}
当我提交空值时,不会显示此自定义错误:
<h:column>
<h:inputText value="#{bean.date}" id="date">
<f:facet name="date">Date</f:facet>
<f:convertDateTime pattern="d.M.yyyy"/>
<f:validator validatorId="dateValidator"/>
</h:inputText>
<h:message for="date" style="color:red"/>
</h:column>
那么如何验证日期字段是否被提交(如果它不是空的)