java - How to get custom message from i18n to model -
i set message constraint this
import play.i18n.messages; public class user extends model { @constraints.required(message = @messages.get("validation.required")) private string login;
but doesn't work.
if want specify customized validation message, must create file named messages
on conf
directory contain customized message first. please check documentation here
then, suppose have model following:
public class mymodel extends model { @constraints.maxlength(value = 4, message = "validation.limit") @constraints.required @column(name = "column_name") public string columnname; }
the messages
files contain following:
validation.limit=please limit input validation.required=this field required fill
notice mark @constraint.maxlength
message
value "validation.limit"
, on messages
file specify value of please limit input
message.
you can find :
if input
columnname
value string length greater4
, validation messageplease limit input
. (corresponding keyvalidation.limit
onmessages
file)if submit empty value on
columnname
, validation messagethis field required fill
. notevalidation.required
default message key@required
annotation.
hope useful you.. ;)
Comments
Post a Comment