Typemismatch tagged with I18N instead of attribute name

My .properties posts contain this by default:

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

The placeholder {0} is replaced with the attribute name. I want to use a shortcut that is used for the interface in this way:

typeMismatch.java.lang.Double = The property {nice label here} must be a valid number.

My first try:

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

doesn't work because message '0' is missing. At this point, the documentation is not clear. Anyone got an idea for this?

Edit:

Well, I can write the error message for each Attribute like this:

typeMismatch.Book.booknumber = Book_Number must be a valid number.

But that seems like a lot of work ...

+2


source to share


4 answers


So I made a small mistake. It's simple now. I'll answer it here. Maybe someone will run into this:

My mistake:

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

      

{0} has been replaced with the name of the attributes.

This was because the Grails API was looking for the correct class names and properties.

For example:

My class is called Book and Property is number.



In the properties of my post:

book.number = Booknumber

      

For i18n everything works fine, but when an error message should happen, it displays the following:

"Property number must be a valid number."

      

Correct version in message properties:

book.number = Booknumber

      

Works for me now. :-)

+2


source


Awesome! Thanks a lot for your post! When it didn't work for me at first, it took me a while to realize that I needed to use the fully qualified class name before the property name. So the syntax is:

package.ClassName.propertyName=Label

      



Very helpful! Thanks again! Al

+1


source


Spring Data Binding Error Validators ("{0}" must be a valid number) want fullClassName.fieldName

Short class name and / or .label not recognized, seeorg.springframework.validation.DefaultBindingErrorProcessor#getArgumentsForBindError

Grails validators ("{0} must be a valid email address") want FQClassName.fieldName.label

or classPropertyName.fieldName.label

Add .label

is required as seen fromorg.codehaus.groovy.grails.validation.AbstractConstraint#rejectValueWithDefaultMessage

Hence, you need both FQN/shortClassName.attributeName.label

and FQN.attributeName

to get the same translatable friendly name in both checks.

http://jira.grails.org/browse/GRAILS-8369

0


source


Another hint, if it helps the next person, if you get an unfriendly error like "Property manufacturer.employeeCount must be a valid number", try adding a property called simply by manufacturer .employeeCount to your messages.properties file as such:

producer .employeeCount = number of employees

At least in Grails 2.0.0, this will result in a friendlier message: "The employee property number must be a real number."

Using the fully qualified class name (eg com.example.domain.Client.employeeCount), with or without the ".label" at the end did not work for me.

Hope this helps someone.

0


source







All Articles