A Bit of Grails Advice
Just finishing my third project in Grails and thought I would mention
a couple of notes.
Install the Templates
Right after creating the project, I install the templates via the command:
grails install-templates
Then edit each of the gsp
files in src/templates/scaffolding
, and put
the following two lines at the top:
<%="\u003C%@ taglib prefix=\"g\" uri=\"/web-app/WEB-INF/tld/grails.tld\" %\u003E"%>
<%="\u003C%@ taglib prefix=\"my\" uri=\"/web-app/WEB-INF/tld/mytaglab.tld\" %\u003E"%>
Those cryptic lines (which don't even correctly compile as JSP files) will link
your editor up to the your tag libs. Both the standard grails one, as well as
your own.
Obviously, you'll want to replace some of the text in the second line.
Customizing the Scaffolding Templates
If you have domain classes, where the CRUD interface is straight-forward, and
the defaults can be good enough, then your controller can be nothing more than:
class ADomainController {
def scaffold = WasteDisposalType
}
Of course, if you go that route, you'll want to customize those templates.
Expanding the Tag Lib TLD Files
That reminds me, why don't the Grails team finish updating the grails.tld
file will all of the tags that they've added. I've had to expand that file
with the following (and it is still not complete) … hrm, maybe I have to
check out the latest 1.1 release to see if it is now complete.
<tag>
<description>Creates a text input field
</description>
<name>textField</name>
<tag-class>org.codehaus.groovy.grails.web.taglib.RenderInputTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>value</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>id</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>class</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<description>Creates a text input field
</description>
<name>textArea</name>
<tag-class>org.codehaus.groovy.grails.web.taglib.RenderInputTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>value</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>id</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>class</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>rows</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>cols</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<description>Creates a text input field
</description>
<name>hiddenField</name>
<tag-class>org.codehaus.groovy.grails.web.taglib.RenderInputTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<description>Renders (or includes) another GSP inside the current one.</description>
<name>render</name>
<tag-class>org.codehaus.groovy.grails.web.taglib.RenderInputTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>template</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>bean</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>model</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>collection</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>var</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>plugin</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<description>Specifies a table header field that can be sorted</description>
<name>sortableColumn</name>
<tag-class>org.codehaus.groovy.grails.web.taglib.RenderInputTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>property</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>defaultOrder</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>title</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>titleKey</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>params</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>action</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
Tell others about this article: