Using HTML collectors in grails instead of GSP

Is there a way to use groovy collectors to create JSP files in a Grails application that support sufficient integration?

To better explain: By default, Grails uses gspfiles that are nice, but rather 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.MarkupBuildertha 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_linkinvented only to give an idea.

+3
source share
3 answers

- grails. , , , xml.

+5

, , " ". SpringMVC views.properties ( views.xml) :

csv=com.example.MyCSVResolver
xml=com.example.MyXMLResolver
audio=com.example.MySpeechResolver

SpringMVC - new ModelAndView(myModel, 'csv') .

CSVResolver, myModel. myModel, , (, ).

Spring , . , JSP .

Grails.... , Grails - API Groovy SpringMVC, SpringMVC Grails. , , , , ModelAndView, , .

+1

GSP allows you to run arbitrary Groovy code inside <%%> brackets. So you can have something like this (an example of borrowing from a page associated with a BlackTiger):

<%      StringWriter w = new StringWriter()
        def builder = new groovy.xml.MarkupBuilder(w)
        builder.html{
            head{
                title 'Log in'
            }
            body{
                h1 'Hello'
                builder.form{ }   
            } 
        }     
    out << w.toString() 
%>

Please note that the above calls to g: form tag, and you can pass additional materials to it.

What you ask for is, of course, possible, although I'm not sure if it will end in victory. I would suggest that you take a look at TagLibs in combination with SiteMesh templates and layouts - it can definitely simplify things.

0
source

Source: https://habr.com/ru/post/1724646/


All Articles