简体   繁体   English

Play Framework 2无法从表单获取数据

[英]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: PASSWORD_RESET_FORM是在同一控制器中声明的字段:

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). 显然,filledForm.hasErrors()返回true,我什么也得不到(因为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 UPD:@ views.html.auth.account.signup._passwordPartial(resetForm)是密码和密码确认字段的模板

@(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. 您的表格使用两个,而您的班级使用三个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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