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));
The short method is
filledForm.reject("name","user already exist");
return badRequest(loginForm.render(filledForm));
You can use withError:
filledForm.withError("name", "user already exist")
You can add a global error too:
filledForm.withGlobalError("eneric error")
From source: https://github.com/playframework/playframework/blob/3bebfa7c1226a438a687ec9a0a3e5c23e5aefa09/framework/src/play/src/main/scala/play/api/data/Form.scala#L252
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With