Validate rich:Legend earlier than other rich:Legend

Asked

Viewed 354 times

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."));
        }

    }
}

1 answer

1

I found the problem! Actually my code is correct the problem was another framework I’m using (Jboss SEAM 2.2),

what happened:

<rich:calendar 
    ...
    value="#{dataInicio}"  // Essa referência é criada e populada pelo JBoss Seam
    ...

<rich:calendar 
    ...
    validator="#{beanController.validateDataFim}" // Essa validação é do JSF
                                                  // O JSF não consegue enxergar
                                                  // dataInicio criada pelo Seam
                                                  // por isso sempre vinha null

Solution!!

<rich:calendar 
    ...
    value="#{beanController.dataInicio}"  // Trocar a referência
    ...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.