geofflane / grails-constraints

Custom constraints plugin for Grails applications
Apache License 2.0
35 stars 11 forks source link

Docs for defaultMessageCode give incorrect message code name #21

Open jonroler opened 11 years ago

jonroler commented 11 years ago

The docs here:

https://github.com/geofflane/grails-constraints/blob/master/README.markdown#defaultmessagecode-property-optional

state that "The default value is default.$name.invalid.message". However, it appears that the actual default value of the defaultMessageCode is default.invalid.$name.message ($name and invalid are in different orders). However, I don't think the fix should be to change the docs. To be consistent with the rest of grails (look at the default messages for the built-in grails constraints as well as the message codes defined for custom constraints by this plugin), I believe the code should be fixed to reflect what the docs say. It looks like the DefaultGrailsConstraintClass is the problem:

public String getDefaultMessageCode() {
    String obj = (String)getPropertyValue(DEFAULT_MESSAGE_CODE_PROPERTY);
    if (obj == null) return "default.invalid." + getConstraintName() + ".message";
    return obj;
}

This line:

if (obj == null) return "default.invalid." + getConstraintName() + ".message";

should change to read:

if (obj == null) return "default."  + getConstraintName() + ".invalid.message";