Вопрос

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.

Это было полезно?

Решение 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.

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top