Reputation: 321
i'm trying addind some errors in forms but my code don't compile.
Expecially, seems that official play 2 api isn't correct.
we can see that errors() return an list of validationError
http://www.playframework.com/documentation/api/2.0/java/play/data/Form.Field.html#errors()
anyway if i try
ValidationError e = new ValidationError("name", "user already exist",new ArrayList());
filledForm.errors().add(e);
i got an error that method add don't exist.
I discovered that it is a hashmap but the follow code don't compile:
filledForm.errors().put("name","s");
How add errors?? thanks
edit: solved thanks Julien Lafont
ValidationError e = new ValidationError("name", "user already exist",new ArrayList());
ArrayList<ValidationError> errors = new ArrayList<ValidationError>();
errors.add(e);
filledForm.errors().put("name",errors);
return badRequest(loginForm.render(filledForm));
Upvotes: 13
Views: 4546
Reputation: 1577
You can use withError:
filledForm.withError("name", "user already exist")
You can add a global error too:
filledForm.withGlobalError("eneric error")
Upvotes: 11
Reputation: 1493
The short method is
filledForm.reject("name","user already exist");
return badRequest(loginForm.render(filledForm));
Upvotes: 12