11 Replies Latest reply on Oct 1, 2009 11:29 AM by alexsmirnov

    Compare Passwords

    joschi03

      Hello,
      I'm actually creating a registration page. In this page a user has to confirm his password. Now, I want to display a message as soon the user has confirmed the password, that password and the confirmation are not equal.
      I already googled a lot, but without success.

      That's what I try:

      <h:outputLabel value="#{msg.password}" />
      <h:inputText id="password" value="#{registerUser.password}">
       <r:ajaxValidator event="onblur" reRender="password"
       ajaxSingle="true" />
      </h:inputText>
      <r:message for="password" />
      
      <h:outputLabel value="#{msg.password_confirm}" />
      <h:inputText id="password_confirm"
       value="#{registerUser.passwordConfirm}">
       <a:support event="onblur" action="#{registerUser.checkPasswords}"
       ajaxSingle="true" />
      </h:inputText>
      <r:message for="password_confirm" />
      


      In the method checkPasswords, I only get the confirmPassword, the password is null.

      Thanks for helping
      joschi03

        • 1. Re: Compare Passwords
          ilya_shaikovsky

          ajaxSingle=true means that only parent input will be processed. so remove it or just add process="password"

          • 2. Re: Compare Passwords
            joschi03

            Hi
            If I remove ajaxSingle="true", then all other fields in the form must be validated as "ok" to run the action.
            But process="password" works! Great!

            Meanwhile I looked at a4j:beanValidator. With this one I have the same problem. Do you have also such a good solution?

            Thanks and regards
            Joschi03

            • 3. Re: Compare Passwords
              ilya_shaikovsky

               


              Meanwhile I looked at a4j:beanValidator. With this one I have the same problem.


              add details.

              • 4. Re: Compare Passwords
                joschi03

                Hi

                <h:outputLabel value="#{msg.password}" />
                <h:inputText id="password" value="#{registerUser.password}">
                 <r:beanValidator />
                </h:inputText>
                <r:message for="password" />
                
                <h:outputLabel value="#{msg.password_confirm}" />
                <h:inputText id="password_confirm"
                 value="#{registerUser.passwordConfirm}"
                 validator="#{registerUser.checkPasswords}">
                 <r:beanValidator />
                </h:inputText>
                <r:message for="password_confirm" />


                Then, the funcion is as follows:
                public void checkPasswords(FacesContext facesContext, UIComponent component, Object value) {...}


                In the field 'value' the value of 'passwordConfirm' is saved, but I cannot access to 'password' to compare them.

                Thanks and regards
                Joschi03

                • 5. Re: Compare Passwords
                  joschi03

                  Hi
                  Does really no one know how to do this?

                  Thanks
                  joschi03

                  • 6. Re: Compare Passwords
                    joschi03

                    Or is there another way, that it seems for the user that the passwords are compared, when he clicks on the register button?

                    Thanks for helping
                    Joschi03

                    • 7. Re: Compare Passwords
                      nbelaevski
                      • 8. Re: Compare Passwords
                        joschi03

                        Hi
                        now I tried it with the graphValidator:

                        <a:form id="registerForm" enctype="multipart/form-data">
                         <r:graphValidator>
                         <h:panelGrid columns="3">
                        
                         <h:outputLabel value="#{msg.password}" />
                         <h:inputText id="password" value="#{registerUser.password}" />
                         <r:message for="password" />
                        
                         <h:outputLabel value="#{msg.password_confirm}" />
                         <h:inputText id="password_confirm" value="#{registerUser.passwordConfirm}" validator="#{registerUser.checkPasswords}" />
                         <r:message for="password_confirm" />
                        
                         <a:commandButton value="#{msg.register}"
                         actionListener="#{registerUser.register}" reRender="name" />
                         </h:panelGrid>
                         </r:graphValidator>
                        </a:form>


                        In checkPasswords(), the variable password is empty. And register() is not even called. But I also get no error...

                        Thanks
                        Joschi03

                        • 9. Re: Compare Passwords
                          joschi03

                          Or does any other way exists, that I can validate all inputs together and compare the password also at the same time. I want stay using hibernate validator for the other inputs. I can also not use immediate=true and/or bypassUpdates=true. The action of the commandButton
                          will be executed, but the other inputs are not validated and updated in the model.

                          Thanks
                          joschi03

                          • 10. Re: Compare Passwords
                            alexsmirnov

                            Validating multiply fields in the JSF a little bit tricky.
                            You got 'null' value for password as null, because you use 'avaxSingle' attribute ( ajaxValidator implicitly set it to 'true'), so no other components are processed by AJAX request and their values does not updated. You have to include both fields into request processing by 'process' attribute or put both fields into one 'a4j:region' component.
                            To multy-fields validation, take a look for beanValidator example that does exactly what you want. You can find its source in the samples/beanValidator forlder from RichFaces source distribution.

                            • 11. Re: Compare Passwords
                              alexsmirnov

                              The graphValidator example at http://livedemo.exadel.com/richfaces-validator/pages/graphValidation.jsf validates total value of three bean properties, that is very close to your needs.
                              To limit validation for password fields only, you can putt them into <a4j:region> component.