Olá Pessoal!
Estou tentando fazer aqui a validação de 2 campos em um cadastro de usuário. Gostaria de verificar se o campo confirmaSenha está igual ao campo senha.
Para fazer esta validação, estou tentando utilizar o validator do JSF, mas não estou conseguindo.
Segue abaixo como estou tentando fazer:
UsuarioMBean
private UIInput senhaInput;
public void validaConfirmaSenha(FacesContext context, UIComponent component, Object value){
if (senhaInput.getLocalValue().equals(value)){
throw new ValidatorException(new FacesMessage("A confirmação está errada"));
}
}
<tr>
<td class="tdLabel">
<label>*Nova Senha:</label>
</td>
<td class="tdCampos">
<h:inputSecret id="novaSenha"
value="#{usuarioMBean.usuario.senha}"
binding="#{usuarioMBean.senhaInput}"
styleClass="inputTxtComum"
style="width:175px;"
maxlength="10">
<f:validateLength minimum="6"/>
</h:inputSecret>
<h:message for="novaSenha" style="color: red" />
</td>
</tr>
<tr>
<td class="tdLabel">
<label>*Confirma Senha:</label>
</td>
<td class="tdCampos">
<h:inputSecret id="confirmaSenha"
value="#{usuarioMBean.usuario.confirmaSenha}"
binding="#{usuarioMBean.confirmaSenhaInput}"
validator="#{usuarioMBean.validaConfirmaSenha}"
styleClass="inputTxtComum"
style="width:175px;"
maxlength="10">
<f:validateLength minimum="6"/>
</h:inputSecret>
<h:message for="confirmaSenha" style="color: red" />
</td>
</tr>
Alguém poderia me ajudar? Dar um exemplo? Dizer oq pode estar errado?
Muito obrigada!