Grails TagLib calling stored body from nested tag -
we setting generalized tag table views.
i need build header cols , content cols. in order provide flexible output content cols want take use of tag body. otherwise use code attribute default output.
the strange thing happens in cell tag:
the first call
//println body?.call(item:[id:4]) // "item 4"
results in expected result. second call (wrapped in closure , temporarily stored in page scope )
//println body?.call(item:[id:4]) // "item"
does not take use of provided closure params.
as seems in cell tag
println "${body.maximumnumberofparameters}" // = 1
and executed @ later point:
println "${body.maximumnumberofparameters}" // = 0
anyone knows more situation or internals of groovypagetagbody?
thx in advance.
taglib:
class pagecomponentstaglib{ def table = { attrs, body -> map model = [:] pagescope._v_cols = [] body() model << [columns:pagescope._v_cols] pagescope.variables.remove('_v_cols') model << [items:attrs.items] out << render(template:'/taglib/p/table', model:model) } def cell = { attrs, body -> //println body?.call(item:[id:4]) // "item 4" //println "${body.maximumnumberofparameters}" // = 1 pagescope._v_cols << [field:attrs.field, headerlabelcode:attrs.headerlabelcode, content:{ item -> //println body?.call(item:[id:4]) // "item" //println "${body.maximumnumberofparameters}" // = 0 body?.call(item:item) }] } }
template:
<table> <thead> <g:each in="${columns}" var="col"> <th><g:message code="${col.headerlabelcode}"/></th> </g:each> </thead> <tbody> <g:each in="${items}" var="item"> <tr> <g:each in="${columns}" var="col"> <td> <g:set var="_v_b" value="${col.content?.call(item)}"/> <g:if test="${_v_b}"> ${raw(_v_b)} </g:if> <g:else> ${item."${col.field}"} </g:else> </td> </g:each> </tr> </g:each> </tbody> </table>
gsp:
<p:table items="${items}"> <p:cell> item ${item?.id} </p:cell> <p:cell field="actor"/> <p:cell field="classname"/> </p:table>
grails version: 2.4.4
Comments
Post a Comment