Search code examples
templatesgrailsmodelrendergsp

how to render template value depending on model param value passed?


I want to render same template on one page which should display the value depending on the param value(3 or 4). View is --

 <td >
<g:render template="gdxqStatusTemplate" model="[param:3]" /> </td>
</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td >
<g:render template="gdxqStatusTemplate" model="[param:4]" /> </td>
</td>

Controller has -

 [ total3:totalValue3,total4:totalValue4]

how to show the appropriate value of total in template code -

<table >
    <tr ><td class="InputText" nowrap><b>   MessageQ Status,/td>

<tr> <td class="NoLight" nowrap>Total MessageQ : ${total+params}***/* IT SHOWS "total4" NOT THE VALUE.*/***
</td></tr>
<tr height=30></tr>
</table>

Solution

  • Yo must change:

     <g:render template="gdxqStatusTemplate" model="[param:3]" />
    

    By

     <g:render template="gdxqStatusTemplate" bean="${total3}" />
    

    And in your template replace:

     <td class="NoLight" nowrap>Total MessageQ : ${total+params}</td>
    

    By:

     <td class="NoLight" nowrap>Total MessageQ : ${it}</td>
    

    For documentation check: http://grails.org/doc/2.0.x/ref/Tags/render.html