[2.0-java] return type of custom validate() method

402 views
Skip to first unread message

Markus Oehme

unread,
Apr 25, 2012, 11:48:30 AM4/25/12
to play-fr...@googlegroups.com
Hello,

the play documentation says, that you can do something like

public class User {
public String name;

public String validate() {
if (name == null)
return "ERROR"
return null;
}
}

This basically works and is does the correct validation for me. My
concern is now, that the ValidationError this is wrapped in has an empty
key in the map Form.errrors(). I would prefer it to have the key "name".
Is this possible? I didn't find any further documentation than the terse
paragraph in the official Play documentation on data validation.

Thanks in advance for all advice

Markus

Kevin Bosman

unread,
Apr 25, 2012, 11:53:00 AM4/25/12
to play-fr...@googlegroups.com
> This basically works and is does the correct validation for me. My concern
> is now, that the ValidationError this is wrapped in has an empty key in the
> map Form.errrors(). I would prefer it to have the key "name". Is this
> possible? I didn't find any further documentation than the terse paragraph
> in the official Play documentation on data validation.

This has been extended in trunk. I'd recommend to either build Play
from source, or wait for official Play 2.0.1

Markus Oehme

unread,
Apr 25, 2012, 12:03:34 PM4/25/12
to play-fr...@googlegroups.com
Thanks, that's exactly what I was looking for. For everybodys amusement
here come the details. It allows three possible signatures for the function:

String validate()
List<ValidationError> validate()
Map<String,List<ValidationError>> validate()

the last one giving full flexibility and the first one beeing the only
allowed one before.

Markus
Reply all
Reply to author
Forward
0 new messages