JSF - validator [RESOLVIDO]

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!
:slight_smile:

Consegui fazer da seguinte maneira:

UsuarioMBean:

private UIInput senhaInput;

public void validateSenha(FacesContext context, UIComponent toValidate, Object value) {
	
	String confirmaSenha = (String) value;
	String senha = (String)this.senhaInput.getLocalValue();

	if (!confirmaSenha.equals(senha)) {
		((UIInput)toValidate).setValid(false);

		FacesMessage message = new FacesMessage(" *Senha Inválida ");
		context.addMessage(toValidate.getClientId(context), message);
	}
}

// Get e Set
public UIInput getSenhaInput() {
	return senhaInput;
}

public void setSenhaInput(UIInput senhaInput) {
	this.senhaInput = senhaInput;
}
<tr>
	<td class="tdLabel">
		<label>*Senha:</label>
	</td>
	<td class="tdCampos">
		<h:inputSecret id="senha"
					   required="true" 
					   binding="#{usuarioMBean.senhaInput}"
					   value="#{usuarioMBean.usuario.senha}" 
					   styleClass="inputTxtComum" 
					   style="width:175px;"
					   maxlength="10">
		<f:validateLength minimum="6"/>
		</h:inputSecret>
		<h:message for="senha" style="color: red" />
	</td>
</tr>

<tr>
	<td class="tdLabel">
		<label>*Confirma Senha:</label>
	</td>
	<td class="tdCampos">
		<h:inputSecret id="confirmaSenha"
					   required="true" 
					   validator="#{usuarioMBean.validateSenha}"
					   value="#{usuarioMBean.usuario.confirmaSenha}" 
					   styleClass="inputTxtComum" 
					   style="width:175px;"
					   maxlength="10">
			<f:validateLength minimum="6" />
		</h:inputSecret>
		<h:message for="confirmaSenha" style="color: red" />
	</td>
</tr>

Não sei se é a melhor maneira, ou a mais elegante, mas foi até onde consegui chegar. :wink:
*creditos: keller

:stuck_out_tongue: :oops: 8)

obrigado .cris por compartilhar a solução … :smiley: me ajudou mto… de verdade :smiley:
não era exatamente esse o meu caso… mas eu precisava descobrir como funcionava o
parametro “validator” :smiley:

tem esse cara aqui… que é mto bom pra esse tipo de validação:

http://www.primefaces.org/showcase/ui/password.jsf

depois da uma olhada :smiley: