i'm trying reduce repetitive gsp code in grails app. following code works 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
map not class property, stated.
however when try dynamically set bunch of these list enum, value attribute not evaluated:
<g:each in="${fields}" var="prop"> <g:textfield name="recordvalues.0.${prop}" value="${recordvalues?.get(0)?.prop}"/> </g:each>
it appears value attribute looking property map key called "prop" , not evaluating variable. i've tried recordvalues?.get(0)[prop]
, without ?
between didn't compile.
is there dynamic method can call variable argument or easier solution?
sorted myself in end. codespace making me check code again , noticing map trying reference, not object property. fact using enum confused issue using regular map.get(var)
did not work, needed map.get(var.name())
instead (maybe i'll encode string field inside enum avoid this).
here's solution:
<g:each in="${fields}" var="prop"> <g:textfield name="recordvalues.0.${prop}" value="${recordvalues?.get(0)?.get(prop.name())}"/> </g:each>
Comments
Post a Comment