Reputation: 13
Javascript of my code
function checkPasswordMatch() {
var password = document.getElementById("password").value;
var confirmPassword = document.getElementById("confirmPassword").value;
if (password != confirmPassword){
alert("Passwords do not match!");
}else{
alert("Passwords match.");
}
}
primefaces jsf code
<h:form>
<h:panelGrid columns="2" id="matchGrid" cellpadding="5">
<h:outputLabel for="pwd1" value="Password 1: *" />
<p:password id="pwd1" value="password" label="Password" required="true" />
<p:message for="pwd1"/>
<h:outputLabel for="pwd2" value="Password 2: *" />
<p:password id="pwd2" value="confirmPassword" onkeyup ="checkPasswordMatch();" label="Confirm Password" required="true" />
<p:message for="pwd2"/>
</h:panelGrid>
<p:commandButton update="matchGrid" value="Save" />
</h:form>
I want to print the alert message in p:message.. is it possible to do so..?? Please help
Upvotes: 0
Views: 2724
Reputation: 4206
You have to use it like PrimeFaces User Guide tells you. The first p:password
component must have the match
attribute, not the second.
If the second p:password
component has match
defined then the following happens. When validating the first p:password
its submitted value is deemed valid (which is already wrong in itself), so it gets set to null, and the local value is set. p:password
match validation works by comparing submitted values. So when validating the second p:password
it thinks that the first component was not filled at all, and declares mismatch.
More on local and submitted values here.
Upvotes: 1