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 greater 4, validation message please limit input. (corresponding key validation.limit on messages file)

  • if submit empty value on columnname, validation message this field required fill. note validation.required default message key @required annotation.

hope useful you.. ;)


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -