grailsinternationalizationgrails-validation

Typemismatch with I18N Label instead of Attribute Name


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...


Solution

  • So I made an little mistake.. it is damm easy now...I'll 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. :-)