In a gsp I'm passing in parameters to a taglib like this:
<g:oneColumnSelect fieldName="gender" from="${['F', 'M']}"
valueMessagePrefix="applicant.gender"
value="${command?.gender}" noSelection="${['':'No answer...']}" />
In the taglib I am assigning the parameters to a model which is then passed to a gsp template like this:
class FormsTagLib {
def oneColumnSelect = {attrs, body ->
out << render(template:"/common/wizard/formselect",
model:[
fieldName:attrs.fieldName,
from:attrs.from,
valueMessagePrefix:attrs.valueMessagePrefix,
optionValue:attrs.optionValue,
value:attrs.value,
noSelection:attrs.noSelection
])
}
I have many of these taglibs where the attrs from the gsp are copied to the model in the tag lib to be rendered in the template. It seems there should be an easier way to copy the attr fields into the model rather than assign each variable one by one.
Something like 'create a new map from an existing map using the existing map keys as the key names and then assigning the original maps values to the new map'.
Any ideas? Just passing in attrs to the template doesn't work.
Just calling
render(template:"/common/wizard/formselect", model:attrs)
Should do it! Have fun!