0
I have 2 date fields, the second may not be previous first, but I’m not able to validate.
Every time you enter the validation dataInicio ALWAYS IS null.
From what I’ve seen of the life cycle of jsf, it makes the first validations for then popular.
and in my case I need the first field to be filled in what is done?
<rich:calendar
id="idDataCadastro"
locale="pt_BR"
popup="true"
value="#{dataInicio}"
datePattern="dd/MM/yyyy"
showInput="true"
label="Data de início"
showApplyButton=""
cellWidth="24px"
cellHeight="22px"
style="width:200px"
required="true" >
</rich:calendar>
<rich:calendar
id="idDataCadastro"
locale="pt,BR"
popup="true"
value="#{dataFim}"
datePattern="dd/MM/yyyy"
showInput="true"
label="Data fim"
showApplyButton=""
cellWidth="24px"
cellHeight="22px"
style="width:200px"
required="true"
validator="#{beanController.validateDataFim}" >
</rich:calendar>
public void validateDataFim(FacesContext context, UIComponent component, Object valor) throws ValidatorException {
if(valor != null){
Date dataFim= (Date) valor;
if(dataInicio != null && dataFim.before(dataInicio)){
throw new ValidatorException(new FacesMessage(
FacesMessage.SEVERITY_ERROR,
"A data fim não pode ser anterior a data inicio.",
"A data fim não pode ser anterior a data inicio."));
}
}
}