我試圖執行重置密碼,但我收到錯誤,但我無法真正理解,錯在哪裏。Play Framework 2無法從表單獲取數據
這是改變密碼類:
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;
}
}
這是由類重置密碼擴展:
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;
}
}
這是我的形式:
@(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>
}{ }
submittion後我得到在控制器中的形式:
final Form<PasswordReset> filledForm = PASSWORD_RESET_FORM.bindFromRequest(request());
PASSWORD_RESET_FORM是在同一個控制器已聲明字段:
private static final Form<PasswordReset> PASSWORD_RESET_FORM = form(PasswordReset.class);
這是結果:
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,[])]})
顯然,filledForm.hasErrors()返回true,我可以得到什麼(因爲值=無)。 任何人都可以指出我的錯誤嗎?
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")
)
是什麼在'@ views.html.auth.account.signup._passwordPartial(ResetForm)重'這個觀點? –
這是新密碼和密碼確認字段的模板。我已更新我的問題,您可以看到源代碼。 – MightySeal
你可以編輯問題來解釋: –