我正在尝试创建一个简单的基于Zentask示例的登录 -- zentask - playframework,但是当我点击调用Application.authenticate操作的登录按钮时,它会给出运行时异常。 我已经标记了错误的行 --
[RuntimeException: java.lang.reflect.InvocationTargetException]
Application.java
public class Application extends Controller {
.........
public static class Login
{
public String email;
public String password;
public String validate()
{
if (User.authenticate(email, password) == null) {
return "Invalid user or password";
}
return null;
}
}
public static Result authenticate()
{
Form<Login> loginForm = form(Login.class).bindFromRequest(); //--- error
if(loginForm.hasErrors()) {
return badRequest(login.render(loginForm));
} else {
session("email", loginForm.get().email);
return redirect(
routes.Application.index()
);
}
}
}
我理解这与Login类中的验证函数有关,因为当我在验证函数中删除对User.authenticate的调用时,它可以正常工作而没有错误。但是我无法弄清楚问题所在。
用户类如下 -
@Entity
public class User extends Model
{
@Id
@Constraints.Required
@Formats.NonEmpty
public String userId;
@OneToOne(cascade=CascadeType.PERSIST)
AccountDetails accDetails;
public static Model.Finder<String,User> find = new Model.Finder<String,User>(String.class, User.class);
// Authenticate the user details
public static User authenticate(String email, String password)
{
String tempId = AccountDetails.authenticate(email, password).userId;
return find.ref(tempId);
}
.. . . . . . .
}
以及AccountDetails类 -
@Entity
public class AccountDetails extends Model
{
@Id
String userId;
@Constraints.Required
String emailId;
@Constraints.Required
String password;
public static Model.Finder<String,AccountDetails> find =
new Model.Finder<String,AccountDetails>(String.class, AccountDetails.class);
public static AccountDetails authenticate(String email, String password)
{
return find.where()
.eq("email", email)
.eq("password", password)
.findUnique();
}
}