I'm trying to reduce some repetitive GSP code in my Grails app. The following code works as expected:
<g:textField name="recordValues.0.name" value="${recordValues?.get(0)?.name}"/>
<g:textField name="recordValues.0.age" value="${recordValues?.get(0)?.age}"/>
[edit]recordValues.0.age is actually a Map not a class property, as I originally stated.
However when I try to dynamically set a bunch of these with a list enum, the value attribute is not evaluated:
<g:each in="${fields}" var="prop">
<g:textField name="recordValues.0.${prop}" value="${recordValues?.get(0)?.prop}"/>
</g:each>
It appears the value attribute is looking for the property Map key called "prop" and is not evaluating it as a variable. I've tried recordValues?.get(0)[prop] with and without ? between but it didn't compile.
Is there some dynamic method I can call with the variable as an argument or an even easier solution?