Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replace <f:all /> tag with normal fields on custom template grails

i install templates in grails 3 and files are in src/main/templates/scaffoldind works fine but use tag

<f:all bean="${propertyName}"/> 

I need a bootsrap twitter class on all inputs and f:all tag do not allow this function, so i need replace tag with individual fields, something like:

    <%
    props.each{
    %>
    <f:field bean="${propertyName}" property="${it.name}">
     <g:textField name="${it.name}" value="${propertyName}?.${it.name}" class="form-control" />
    </f:field>
...
    <%
    }
    %>

I found this article http://www.jakusys.de/blog/2008/12/grails-scaffolding-in-depth/ but is for grails 2 not grails 3, some solution for replace f:all tag for normal inputs or add class "form-control" to all f:all inputs

like image 445
Abel Olguin Chavez Avatar asked Sep 26 '22 00:09

Abel Olguin Chavez


2 Answers

If you want to make all fields rendered by <f:all /> look nice and bootstrappy, you'll need to create _field.gsp templates for them.

You can create common templates (used for all fields) by creating these four gsp fragments:

_wrapper.gsp
_widget.gsp
_displayWrapper.gsp
_displayWidget.gsp

in this directory:

grails-app/views/_fields/default/

You can then replace the

<%
props.each{
%>
<f:field bean="${propertyName}" property="${it.name}">
 <g:textField name="${it.name}" value="${propertyName}?.${it.name}" class="form-control" />
</f:field>
...
<%
}
%>

bit in your scaffolding gsp with a call to the <f:all /> tag.

See documentation here

like image 77
rcgeorge23 Avatar answered Oct 11 '22 00:10

rcgeorge23


This doesn't work for <f:display bean="${propertyName}" /> with me when I was trying to show all properties (without editing), so here is what I did to get works properly, I've created two files the first /views/_fields/default/_displayWidget.gsp with this template:

<tr class="prop">
    <td valign="top" class="name">${label}</td>
    <td valign="top" class="value">${value}</td>
</tr>

and the second /views/templates/_fields/_list.gsp using this template:

<g:each in="${domainProperties}" var="p">
    ${body(p)}
</g:each>

Actually I've just overwrite the original template _list.gsp (I'm using grails v3.1).

like image 36
Ibrahim.H Avatar answered Oct 11 '22 02:10

Ibrahim.H