【发布时间】:2015-07-30 08:29:58
【问题描述】:
我有Login 类和validate 方法如下:
public static class Login {
/** The customer. */
@ManyToOne
@Constraints.Required
public Customer customer;
/** The password. */
public String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Customer getCustomer() {
return this.customer;
}
public void setCustomer(Customer c) {
this.customer = c;
}
/**
* Validate.
*
* @return the string
*/
@Transactional
public String validate() {
return "Global error";
}
}
表单绑定代码:
Form<Login> filledLoginForm = form(Login.class);
filledLoginForm.bindFromRequest();
当我按如下方式验证表单时:
if (filledLoginForm.hasGlobalErrors()) {
return badRequest(views.html.login.render(filledLoginForm));
} else if (filledLoginForm.hasErrors()) {
return badRequest(views.html.login.render(filledLoginForm));
} else {
return ok("OK");
}
查看:
<input type="hidden" id="customer_id" name="customer.id" value="@customer.id" />
@inputPassword(
LoginForm("password"),
'_label -> "Hasło",
'_showConstraints -> false,
'_showErrors -> false
)
我得到好的页面,就像没有错误一样,但是在验证方法中我已经声明了它。
我使用 play 2.2.6
【问题讨论】:
-
请贴出你如何做表单绑定的代码
-
我已经发布了。你是这个意思吗?我没有更多了。
-
还发布此
Login对象由用户填充数据的视图。客户是如何被选中的?
标签: java forms playframework-2.2