<html xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns="http://www.w3.org/1999/xhtml"> <html> Password: <h:inputsecret binding="#{passwordComponent}" id="pwd" required="true" requiredmessage="Enter Password" styleclass="inputText" value="#{registerBean.password}"> Confirm Password: <h:inputsecret id="confirm" required="#{not empty passwordComponent.value}" requiredmessage="Enter Confirm Password" styleclass="inputText" validator="#{registerBean.validatePassword}" value="#{registerBean.confirmPassword}"> <f:attribute name="passwordComponent" value="#{passwordComponent}"> </f:attribute></h:inputsecret> </h:inputsecret></html> //File: RegisterBean.java: import javax.faces.application.FacesMessage; import javax.faces.component.UIComponent; import javax.faces.component.UIInput; import javax.faces.context.FacesContext; import javax.faces.validator.ValidatorException; public class RegisterBean{ String password; String confirmPassword; public void validatePassword(FacesContext context, UIComponent toValidate, Object value) { String confirm = (String) value; UIInput passComp = (UIInput) toValidate.getAttributes().get("passwordComponent"); String password=(String)passComp.getValue(); if (!password.equals(confirm)) { FacesMessage message = new FacesMessage("Password and Confirm Password Should match"); throw new ValidatorException(message); } } }