Skip to content

Using respond with a custom model name  #66

@bessb

Description

@bessb

It appears that if I use respond then the model name is determined by the type e.g.

class HelloController  {

    static responseFormats = ['json']

    def test() {
        def messages = [
            [hello: 'world'],
            [foo: 'bar']
        ]
        respond messages
    }
}

My view has to look like this:

model {
    List linkedHashMapList
}
json {
    messages linkedHashMapList
}

If I don't use respond, and simply return a Map from my action, then I can use whatever model name I want in my view:

class HelloController  {

    static responseFormats = ['json']

    def test() {
        def messages = [
            [hello: 'world'],
            [foo: 'bar']
        ]
        [messages: messages]
    }
}
model {
    List messages
}
json {
    messages messages
}

Is there a way to use respond and use a custom name for the model? It appears that passing a model argument to respond does not work, it still uses the name determined by type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions