简体   繁体   中英

Play Framework 2 unable to get data from form

I'm trying to implement reset password and i'm getting errors, but i can't really understand, what am doing wrong.

this is class for changing password:

public static class PasswordChange {

    @MinLength(6)
    @Required
    public String password;

    @MinLength(6)
    @Required
    public String repeatPasssword;

    public String getPassword() {
        return password;
    }

    public String getRepeatPasssword() {
        return repeatPasssword;
    }

    public void setRepeatPasssword(String repeatPasssword) {
        this.repeatPasssword = repeatPasssword;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String validate() {
        if (password == null || !password.equals(repeatPasssword)) {
            return Messages.get("auth.change_password.error.passwords_not_same");
        }
        return null;
    }
}

which is extended by class for resetting password:

public static class PasswordReset extends Account.PasswordChange {

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String token;  

    public PasswordReset() {}

    public PasswordReset(final String token) {
        this.token = token;
    }

}

This is my form:

@(resetForm: Form[controllers.Signup.PasswordReset])

@import helper._
@import helper.twitterBootstrap._

@main(Messages("auth.password.forgot.title")){

<p>
@form(routes.Signup.doResetPassword()) {
    @if(resetForm.hasGlobalErrors) {
        <p class="error">
            <span class="label label-important">@resetForm.globalError.message</span>
        </p>
    }

    @views.html.auth.account.signup._passwordPartial(resetForm)

    <input type="hidden" name="token" id="token" value='@resetForm("token").value' />

    <input type="submit" value="@Messages("auth.change.password.cta")" class="btn btn-primary">
}
</p>

}{ }

After submittion i get form in controller:

final Form<PasswordReset> filledForm = PASSWORD_RESET_FORM.bindFromRequest(request());

PASSWORD_RESET_FORM is field declared in the same controller:

private static final Form<PasswordReset> PASSWORD_RESET_FORM = form(PasswordReset.class);

And this is the result:

Form(of=class controllers.Signup$PasswordReset,
    data={token=e2d48b70-9d00-4b8f-a8e4-ee17089c4e22,
    repeatPassword=1234567, password=1234567},
    value=None,
    errors={repeatPasssword=[ValidationError(repeatPasssword,error.required,[])]})

Obviously, filledForm.hasErrors() returns true and i can get nothing (because value=None). Can anyone point me on my mistake?

UPD: @views.html.auth.account.signup._passwordPartial(resetForm) is a template for password and password confirm fields

@(f: Form[_])

@import helper._
@import helper.twitterBootstrap._

@inputPassword(
    f("password"),
    '_label -> Messages("auth.password.placeholder")
)

@inputPassword(
    f("repeatPassword"),
    '_label -> Messages("auth.password.repeat"),
    '_showConstraints -> false,
    '_error -> f.error("password")
)

You need to decide how many s in password. Your form uses two while your class uses three.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM