开发者

Use Aliases for Validation to show gramatically correct error messages - play framework

My question refers to validation in a Model class. I know how to basically do validation, but I've though got a question about it.

I'd like to now if it is possible to use a alias in validation? Because it should display a german message, and mixed up with my English database field name it looks really strange.

So, without an alias my code in the model class would be

@Equals("password")
@Required
public String passwordConfirm;

So password has to equal with passwordCo开发者_StackOverflow中文版nfirm (passwordConfirm = "Bestätigung des Passworts" in German, password="Passwort" :) Which would print, if a error occurs: "Bestätigung des Passworts muss mit password übereinstimmen." (should be "Passwort", not "password")

So do I need to define an alias or something, or how could this work?

greetings


You should be able to use the "message" variable for that, to override the output of the validation.

@Equals({value="password", message="key.to.messages.i18n")

This will let you define the validation messages in I18N files.

Disclaimer: don't have the code here, but it's something like this, beware of typos :P

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜