Reputation: 81
I run the sample code in play 2.2 "comuputer-database-jpa"
In the Conf/Messages
# Messages
computers.list.title={0,choice,0#No computers|1#One computer|1<{0,number,integer} computers} found
I want to used this conditional messages in my error messages to make my error message as dynamic as possible. In my code say that i'm passing 2 parameters and 1 of it is the message id.
@Messages(messageId,errors(1).getOrElse(""),errors(2).getOrElse(""))
equivalent to
@Messages(error.format,FIRST NAME)
can also be
@Messages(error.format,EMAIL)
How can i use the conditional conf/messages in my code? I tried some using the sample and an error occurred. Code:
error.format = Enter {0,choice,FIRST NAME#{0} in half-width alphanumeric|EMAIL#{0} in valid format.}
What am i doing wrong?
Upvotes: 0
Views: 107
Reputation: 82
The below code will yield what you are looking for
//html<br/>
@Messages("error.format",2, "name error","email error")
Number 2 in the example above will show the message "EMAIL in valid format". if you change it to 1 it will show the message "FIRST NAME in half-width alphanumeric"
//messages<br/>
error.format = Enter {0,choice,1#FIRST NAME in half-width alphanumeric|2#EMAIL in valid format.}
Upvotes: 1