Hi buddies,
I need validate my form just on form submit, but it isn't hapen 'cause when i
change first field, unfortunately, this invoke validation mapped on component
before affect other component.
Someone know how avoid this and int this case affect the second field?
Below i post my code.
Thank's in advance.
======== XHTML
===============================================================
<code>
<p:calendar id="dataInicial" style="width: 10px"
value="#{filtroBean.dataInicial}" maxlength="10"
pattern="#{msgs['global.mascara.data.diaMesAno']}"
maxdate="#{filtroBean.dataFinal}"
required="true"
requiredMessage="#{msgs['global.validacao.dataInicial.requerido']}"
converterMessage="#{msgs['global.validacao.dataInicial.invalida']}"
validator="validadorDataInicial"
showButtonPanel="true" navigator="true" effect="fade"
readOnlyInputText="true">
<p:ajax
event="dateSelect" update="totaisTerminalServicoForm" />
</p:calendar>
<p:spacer width="5px"
/>
<h:outputLabel
for="dataFinal" value="#{msgs['global.dataFinal2P.label']}" />
<p:calendar
id="dataFinal" value="#{filtroBean.dataFinal}" maxlength="10"
pattern="#{msgs['global.mascara.data.diaMesAno']}"
mindate="#{filtroBean.dataInicial}"
required="true"
requiredMessage="#{msgs['global.validacao.dataFinal.requerido']}"
converterMessage="#{msgs['global.validacao.dataFinal.invalida']}"
showButtonPanel="true" navigator="true" effect="fade"
readOnlyInputText="true">
<p:ajax
event="dateSelect" update="totaisTerminalServicoForm" />
</p:calendar>
</code>
======== *JSF VALIDATOR*
=====================================================
<code>
@FacesValidator(value="validadorDataInicial")
public class ValidadorDataIniciallFiltro implements Validator{
@Override
public void validate(FacesContext context, UIComponent component,
Object value) throws ValidatorException {
String dataFinalId = String.format("%s:%s",
component.getClientId().substring(0,
component.getClientId().indexOf(":")),
"dataFinal");
UIInput dataFinalInput = (UIInput)
context.getViewRoot().findComponent(dataFinalId);
Date dataInicial = (Date) value;
Date dataFinal = (Date) dataFinalInput.getValue();
if(dataInicial.after(dataFinal)){
throw new ValidatorException(new
FacesMessage(FacesMessage.SEVERITY_ERROR,
TDSUtils.getMessage("global.validacao.dataFinal.posterior"), null));
}else if((dataFinal.getTime() - dataInicial.getTime()) /
86400000 > 31){
throw new ValidatorException(new
FacesMessage(FacesMessage.SEVERITY_ERROR,
TDSUtils.getMessage("global.validacao.pediodoDatas.invalido"), null));
}
}
}
</code>
--
[Message sent by forum member 'paulonep']
View Post: http://forums.java.net/node/883002