I follow the tutorial at http://www.playframework.org/documentation/2.0/JavaForms
I created the LoginForm.java class (instead of the User.class example from the example. Not for the class that is saved, just to store form values)
package domain; import static play.data.validation.Constraints.*; public class LoginForm { @Required public String email; public String password; }
And in my controller I do (as an example), but I set the values ββfor blank lines to try the @Required annotation.
Form<LoginForm> loginForm = form(LoginForm.class); Map<String,String> anyData = new HashMap(); anyData.put("email", ""); anyData.put("password", ""); //Faking a post LoginForm postedLoginForm = loginForm.bind(anyData).get(); if(loginForm.hasErrors()) { //Just for this test task, should have another error handling.. return ok("@Required annotation kicked in.."); } else { return ok("Got form values, email: " + postedLoginForm.email + " password: " + postedLoginForm.password); }
But with:
LoginForm postedLoginForm = loginForm.bind(anyData).get();
I get an Execution exception [[IllegalStateException: No value]]
Therefore, he never checks / never comes in
if(loginForm.hasErrors())
Does anyone know why this is? If I set the values ββas an example:
Map<String,String> anyData = new HashMap(); anyData.put("email", " bob@gmail.com "); anyData.put("password", "secret");
Everything works, and I get a LoginForm object with the correct values. Should I catch the exception? You should not take care of this and set loginForm.hasErrors = true?
Thanks for any help!
John rodrick
source share