Grails 2.3.1 Command Object Data Binding at Controller Parameters

女生的网名这么多〃 提交于 2019-12-25 05:09:33

问题


I recently upgrade from grails 2.2 to 2.3.1. My controller used to bind data to an command object at controller parameters. After I upgraded to 2.3.1, the binding seems not working and have '[Fatal Error] :-1:-1: Premature end of file.' output to console.

it works fine at 2.2 like this def home(ACommand cmd) {}

after upgrading, it outputs 'Premature end of file' before it goes to the action and skip the action method and going to home.gsp view directly.

I also tried new an instance inside the action and use bindData(cmd, params). When I step through the action, bindData method produced the same message but can continue and generate view models and pass to home.gsp.

Does anyone happen to know what might cause the problem? Thanks.


回答1:


Grails 2.3 includes a new data binding mechanism which has additional features. If you need to access the legacy spring data binding mechanism use this configuration in Config.groovy

grails.databinding.useSpringBinder=true

Eventually if you feel the need to use the latest data binder then a transition to use the new features would be needed.




回答2:


Thanks dmahapatro. I tried it before but does not work.

FYI, I fixed it by rearranging content negotiations at Config.groovy.

Changing from

mime.types = [ xml: ['text/xml', 'application/xml'],
        text: 'text/plain',
        js: 'text/javascript',
        rss: 'application/rss+xml',
        atom: 'application/atom+xml',
        css: 'text/css',
        csv: 'text/csv',
        all: '*/*',
        json: 'text/json',
        html: ['text/html','application/xhtml+xml']
]

to

mime.types = [
        all:           '*/*',
        atom:          'application/atom+xml',
        css:           'text/css',
        csv:           'text/csv',
        form:          'application/x-www-form-urlencoded',
        html:          ['text/html','application/xhtml+xml'],
        js:            'text/javascript',
        json:          ['application/json', 'text/json'],
        multipartForm: 'multipart/form-data',
        rss:           'application/rss+xml',
        text:          'text/plain',
        hal:           ['application/hal+json','application/hal+xml'],
        xml:           ['text/xml', 'application/xml']
]

Solves the problem.

Not sure why the order matters, but I think it is caused by Grails 2.3 databinding intend to parse request body and bind to my command object and lead to an xml parser error.



来源:https://stackoverflow.com/questions/19828274/grails-2-3-1-command-object-data-binding-at-controller-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!