Reputation: 1
Iterating list(pedaTechList) in GSP page using g:each tag and building image with different URLS. The problem is I am always getting first element of pedaTechList for "${ped.id}" while building the URL for assign below. The code snippet is below. Please help to resolve this.
<g:each in="${pedaTechList}" var="ped" >
<div class="imgblock">
<img style="height: 130px;" src="${resource(dir: 'images', file: 'unfav-unchecked.png')}" alt="Criteria" usemap="#p_icons" />
<div class="smallblackarea">
<map name="p_icons">
<area shape="rect" coords="0,0,18,18" href="${createLink(controller: 'pedagogy', action: 'reloadPedagogyTab', id: imod?.id, params: [objectiveId: params.objectiveId, fav:'true', assign:'false'])}" title="Favorite" alt="Favorite" />
**<area shape="rect" coords="90,0,126,24" href="${createLink(controller: 'pedagogy', action: 'reloadPedagogyTab', id: imod?.id, params: [objectiveId: params.objectiveId, pedtecID: "${ped.id}", fav:'false', assign:'true'])}" title="Assign" alt="Assign" />**
<area shape="rect" coords="90,90,200,200" href="http://www.google.com/" title="Clone" alt="Clone" />
</map>
${ped.pedagogyTitle}
</div>
</div>
</g:each>
Upvotes: 0
Views: 171
Reputation: 5310
Here is an explanation: http://blog.freeside.co/post/46587122020/groovy-gotcha-for-loops-and-closure-scope
Gstrings contain closures which get evaluated later in this case. In your example you can replace pedtecID: "${ped.id}" with pedtecID: ped.id or pedtecID: "${ped.id}" as String
Upvotes: 0