views:

230

answers:

2

My message.properties contains this by default:

typeMismatch.java.lang.Double=Property {0} must be a valid number

Placeholder {0} is replaced by the Attribute Name. I want to use the Label that is used for the frontend like this:

typeMismatch.java.lang.Double=Property {wonderful label here} must be a valid number.

My first Attempt:

typeMismatch.java.lang.Double=Property ${message(code:'0')} must be a valid number.

is not working cause there is no '0' message. Documentation is not clear at that point. Anyone got an idea for this one?

Edit:

Well i can write an error message for every Attribute like this:

typeMismatch.Book.booknumber = Property Booknumber must be a valid number.

But this seems like a lot of extra work...

A: 

So I made an little mistake.. it is damm easy now...i answer it here. Maybe someone will run into this:

My Mistake was:

typeMismatch.java.lang.Double=Property {0} must be a valid number {0} was replaced by the Attributes Name.

The Reason behind that was that Grails API rendererror is looking for correct Classnames and Properties.

For example:

My Class is named Book and Property is number.

In my message properties: book.number = Booknumber

For i18n everything worked fine, but when the error message has to occur it shows the following: "Property number must be a valid number."

Correct Version in message properties:

Book.number = Booknumber

Works for me now. :-)

bastianneu
A: 

Awesome! Thanks so much for your post! When it didn't work for me at first, it took me some time to realize that I needed to use the fully qualified class name in front of the property name. So the syntax is:

package.ClassName.propertyName=Label

Very useful! Thanks again! Al

Al Belsky
Thank you for your answer.
bastianneu