I have an domain called Project with a hasMany relationship like
class Project {
static hasMany = [prefixes: Prefix]
}
In the Project show.gsp using <f:display bean="project" /> the list of Prefix displays the id's like com.example.Prefix:1
I want to replace this with something more meaningful by concatenating two properties of Prefix like 'number' and 'name' with a hyphen in between. In Grails 2 without Fields plugin I would have done something like this:
<ol>
...
<li class="fieldcontain">
<span id="prefixes-label" class="property-label">
<g:message code="prefixes.label" default="Prefixes" /></span>
<g:each in="${project.prefixes}" var="p">
<span class="property-value" aria-labelledby="prefixes-label">
<g:link controller="prefix" action="show" id="${p.id}">${p.number} - ${p.name}</g:link></span>
</g:each>
</li>
...
</ol>
I've tried creating a grails-app/views/project/show/_displayWrapper.gsp with the above code except replacing 'project' with 'bean' and the <f:display bean="project"> in show.gsp but I still got the default page.
How do I use the <f:display bean="project"> style tag to achieve this?
Thanks, Carl
I got it working by creating a default views/project/show/_displayWrapper.gsp for my regular properties:
<li class="fieldcontain">
<span id="${label}" class="${label}"><g:message code="${label}" default="${label}" /></span>
<span class="property-value" aria-labelledby="${label}"><g:fieldValue bean="${project}" field="${property}"/></span>
</li>
And a specific one for my hasMany prefixes in views/project/show/prefixes/_displayWrapper.gsp
<li class="fieldcontain">
<span id="${label}" class="${label}"><g:message code="${label}" default="${label}" /></span>
<g:each in="${value}" var="p">
<span class="property-value" aria-labelledby="${label}"><g:link controller="prefix" action="show" id="${p.id}">${p.number} - ${p.name}</g:link></span>
</g:each>
</li>
And then in my show.gsp I replaced
<f:display bean="project" />
With
<ol class="property-list">
<f:display bean="project" property="number"/>
<f:display bean="project" property="name"/>
...
<f:display bean="project" property="prefixes"/>
</ol>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With