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 ...
source to share
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. :-)
source to share
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.
source to share
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.
source to share