Closed manishkbharti closed 4 years ago
Workaround --
command.aDate = params.date('aDate', message(code: 'date.field.format'))
command.clearErrors()
command.validate()
and implements CO with grails.validation.Validateable trait.
@puneetbehl I did some research on this, here is what i found
grails.web.databinding.GrailsWebDataBinder#getFormatString:653
, in this method, messageSource
is null so we get a NPE. the error that rendered is then basically that the property in the Command object is null. protected String getFormatString(Annotation annotation) {
assert annotation instanceof BindingFormat
def code
if(annotation instanceof BindingFormat) {
code = ((BindingFormat)annotation).code()
}
def formatString
if(code) {
def locale = getLocale()
formatString = messageSource.getMessage((String) code, [] as Object[], locale)
}
if(!formatString) {
formatString = super.getFormatString(annotation)
}
formatString
}
I also ran it on 3.3.11 and the messageSource
to get date.field.format
exists, but the property string doesn't exist in this grails version. The message source is of type PluginAwareResourceBundleMessageSource
. This is also the type that is used when the user did the line println "code message= ${g.message(code: 'date.field.format')}="
in his sample to demonstrate that the field actually exists
Therefore, i think the root of the issue may be that GrailsWebDataBinder
is not created with the messageSource populated.
More notes 6/25
messageSource
is injected during bean creation of GrailsWebDataBinder
. In grails 3.3.11, the messageSource
is set with the setter and it is tagged with @Autowired
. There is a DSL bean creation closure in DataBindingGrailsPlugin
, but some properties are set, not the messageSource
GrailsWebDataBinder
is created with a constructor in DataBindingConfiguration
, but the messageSource
is never set directly. GrailsWebDataBinder
also has a setting with @Autowired. ** Maybe this is not working in the new Grails bean creation.
There is also AbstractDataBindingGrailsPlugin
which has the bean DSL, similar to what happens in grails 3. Above i submitted a pr to fix this
Task List
Steps to Reproduce
Expected Behaviour
Localized BindingFormat should give the expected date.
Actual Behaviour
Localized BindingFormat giving null.
Environment Information
Example Application