I have a problem with form validation within a wizard. The wizard is used for
account setup which concludes in setting a password as the final step.
Originally this wasn't inside a wizard, but a panel with an embedded form.
As I was dealing with this panel, I added it to the wizard, disabling the
form buttons. Now I had to add form validation again and used an
AbstractFormValidator (see below). It usually works, but occasionally the
form seems to be submitted multiple times although I clicked "Finish" only
once. I rarely can reproduce it, but it happens to our users every now and
then.

Maybe someone can shed light on what I might be doing wrong.

The method below is called in the constructor of the WizardStep, and just so
you know, the form component "password2" has validators checking if the
required number of letters, numbers, special characters etc. are fulfilled.

    private void addFormValidator(){
      add(new AbstractFormValidator() {
            public FormComponent[] getDependentFormComponents() {
                try{
                    log.debug("{}:{}: Retrieving form coponents", uniqueId,
midm);
                    FormComponent passwd = (FormComponent)
passwordPanel.getPasswordForm().get("password");
                    FormComponent passwd2 = (FormComponent)
passwordPanel.getPasswordForm().get("password2");
                    log.debug("{}:{}: Found 2 form coponents", uniqueId,
midm);
                    return new FormComponent[] { passwd, passwd2 };
                } catch (Exception e){
                    return null;
                }
            }

            public void validate(Form form) {

                try {
                    log.debug("{}:{}: Before password change", uniqueId,
midm);
                   
passwordPanel.changePassword(passwordPanel.getNewPassword(), null);
                    log.debug("{}:{}: After password change", uniqueId,
midm);
                    if (!authenticated){
                        log.debug("{}:{}: Before authentication", uniqueId,
midm);
                        authenticateUser();
                        log.debug("{}:{}: After authentication", uniqueId,
midm);
                    }
                } catch (UnavailableDataSourceException e) {
                    form.error("There was a database error changing your
password, please try again later.");
                } catch (UpdatePasswordException e) {
                    form.error("There was an error changing your password: "
+ e.getMessage());
                } catch (PreviousPasswordException e) {
                    form.error("The submitted password was previously used!
Please choose a " +
                    "different password");
                } catch (ExpiredPasswordException e) {
                    log.error("{}:{}: Unable to update password for user,
reason: " + e.getMessage(), 
                                uniqueId, midm);
                    form.error ("An internal error occurred while updating
your password, the password was NOT changed!");
                } catch (ServicePasswordIsMidasPasswordException e) {
                    form.error("The submitted service password was your
MIDAS password. " +
                     "This is not allowed.");
                } catch (ErrorUserCreationException e) {
                    log.error("{}:{}: Unable to update password for user,
reason: " + e.getMessage(), 
                                uniqueId, midm);
                    form.error ("An internal error occurred while updating
your password, the password was NOT changed!");
                } catch (PasswordChangedTodayException e) {
                    form.error("Your password can only be changed once a
day!");              
                } catch (PasswordExpirationUpdateException e) {
                    log.error("{}:{}: Unable to update password for user,
reason: " + e.getMessage(), 
                                uniqueId, midm);
                    form.error ("An internal error occurred while updating
your password, the password was NOT changed!");
                } catch (Exception e) {
                    log.error("{}:{}: Unable to update password for user,
reason: " + e.getMessage(), 
                                uniqueId, midm);
                    form.error ("An internal error occurred while updating
your password, the password was NOT changed!");
                }
            }
      }); 
    }

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/AbstractFormValidator-in-Wizard-tp4665164.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to