Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Check two passwords via CustomValidation in JSF  RSS feed

 
veli akcakaya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i'm new in JSF.

i have design a registration form. I want to check that are passwords equal. i wrote a custom validation method for this reason in my bean class. it is;

public void passwordValidate(FacesContext arg0, UIComponent arg1, Object val) throws ValidatorException {
System.out.println("this.getPassword2()=" + val.toString());
System.out.println("this.getPassword()=" + this.getPassword());
if(!this.getPassword2().equals(this.getPassword())) {
throw new ValidatorException(new FacesMessage("Passwords don't match"));
}
}

And i use it in the form this type;

<a4j:form id="registerForm">
....
<hutputText value="#{msg.password}" />
<h:inputSecret id="RegPasswd" value="#{regForm.password}" required="true" autocomplete="false" />
<rich:message for="RegPasswd"/>

<hutputText value="#{msg.password_again}" />
<h:inputSecret id="RegPasswd2" value="#{regForm.password2}" size="14" maxlength="16" required="true" validator="#{regForm.passwordValidate}">
<a4j:support ajaxSingle="true" event="onblur"></a4j:support>
</h:inputSecret>
<rich:message for="RegPasswd2"></rich:message>
...
<a4j:commandButton value="#{msg.login}" action="#{regForm.doSimpleRegister}" />
</a4j:form>

But i can't get first password inputSecret value via this.getPassword() method. getPassword() is in the same Bean file. How can i get first password and check them.

Thanks,

veli akcakaya
http://www.BT-tr.net
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read on about the JSF lifecycle. The bean properties are set in the update model values phase. The validation happens in the validations phase, which is right before the update model values phase.

You need to use the value which is been passed as parameter of the validator method. You can use f:attribute to specify the ID of another password component and get it by UIViewRoot#findComponent() and get its value then.

Also see this example: http://balusc.blogspot.com/2007/12/validator-for-multiple-fields.html
 
veli akcakaya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
so thanks for your reply. I solved my problem with your help.

Have a nice day.

veli akcakaya
http://www.BT-tr.net
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!