Forums Register Login

Check two passwords via CustomValidation in JSF

+Pie Number of slices to send: Send
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">
....
<h:outputText value="#{msg.password}" />
<h:inputSecret id="RegPasswd" value="#{regForm.password}" required="true" autocomplete="false" />
<rich:message for="RegPasswd"/>

<h:outputText 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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Hi,
so thanks for your reply. I solved my problem with your help.

Have a nice day.

veli akcakaya
http://www.BT-tr.net
+Pie Number of slices to send: Send
You're welcome.
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 3976 times.
Similar Threads
I need help with ajaxSingle, reRender and immediate.
Validation skip
JSF RichFaces Facelets integration problem
It seems the code JSF 2.0 controls aren't updating backing beans
Backing Bean Behaviour on MyFaces using A4J
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 05:37:16.