Search code examples
javagrailsgroovygsp

Using HTML builders in grails instead of GSP


is there a way to use groovy builders to build JSP files in a Grails application keeping things enough integrated?

To explain better: by default Grails uses gsp files that are nice but quite verbose..

<div class="clear">
  <ul id="nav">  
    <li><g:link controller="snippets" action="list">Snippets</g:link></li>
    <li><g:link controller="users" action="list">Users</g:link></li>
    <li><g:link controller="problems" action="list">Problems</g:link></li>
    <li><g:link controller="messages" action="list">Messages</g:link></li>
  </div>
<div id="content">

is there a way to use groovy.xml.MarkupBuilder tha would turn the previous piece into

div(class:'clear') {
  ul(id:'nav') {
    li { g_link(controller:'snippets', action:'list', 'Snippets') }
// and so on

Of course g_link is invented just to give the idea..


Solution

  • Do a search for builder under the web layer section of the grails user guide. There is an example in there that shows you exactly how to do this using the xml builder.