Say I have a controller action like the following:
def someAction = {
if (someCondition) {
[foo: 1, bar: 2]
} else {
[foo2: 4, bar2: 6, baz2: 6]
}
}
In someAction.gsp I don’t know what the keys of the model are. Is there some way that I can iterate over the keys and values of the model without knowing the key names?
All model attributes are available in the
requestobject. You can iterate this object like this:Note that the
requestobject will hold all request attributes, a lot of information that you’re probably not interested in.Another way to accomplish what you want is putting all your model attributes in one map, like this:
This way you can isolate your attributes from other request attributes. In this case you’ll have to iterate your model keys using the
resultmap: