Sunday, June 19, 2016

Grails fiels f:table f:all

Grails uses the field plugin to generate templates for your GSP.
So for instance your gsp with
<fieldset class="form">
    <f:all bean="project"/>
</fieldset>
Will show a form for all the fields on a Bean.
And the following will show a table view

<f:table collection="${projectList}" />
But what if you want to override the styling, that is easy!
But where do you start, it took me a while to find the default templates that are used, you can find them in the plugin.

So right here is the tables one:
<table>
<thead>
<tr>
<g:each in="${domainProperties}" var="p" status="i">
<g:set var="propTitle">${domainClass.propertyName}.${p.name}.label</g:set>
<g:sortableColumn property="${p.name}" title="${message(code: propTitle, default: p.naturalName)}" />
</g:each>
</tr>
</thead>
<tbody>
<g:each in="${collection}" var="bean" status="i">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<g:each in="${domainProperties}" var="p" status="j">
<g:if test="${j==0}">
<td><g:link method="GET" resource="${bean}"><f:display bean="${bean}" property="${p.name}" displayStyle="${displayStyle?:'table'}" /></g:link></td>
</g:if>
<g:else>
<td><f:display bean="${bean}" property="${p.name}" displayStyle="${displayStyle?:'table'}" /></td>
</g:else>
</g:each>
</tr>
</g:each>
</tbody>
</table>

1 comment: