Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Tag Library in grails not passing HTML tags out properly

Tags:

grails

taglib

I am learning grails using the definitive guide to grails 2 (using grails 2.3.7), and when I'm looking at the custom tag library it gives an example custom tag as follows:

    def repeat = { attrs, body ->
        int n = attrs.int('times)
        n?.times { counter ->
              out << body(counter +1)
        }
    }

so when I use this tag like so:

   <g:repeat times="3">
      Hello number ${it}<br>
   </g:repeat>

I expect to get three separate lines on my rendered HTML:

   Hello number 1
   Hello number 2     
   Hello number 3

Instead I get:

   hello number 1<br>hello number 2<br>hello number 3<br>

I have found methods that look like they should help, like decodeHTML() however I am thus unable to change the output that I want, and I'm not sure what I'm doing wrong.

I have tried doing:

   out <<body.decodeHTML()

but I get a null pointer error...

like image 882
Ted Delezene Avatar asked Jan 10 '23 19:01

Ted Delezene


1 Answers

That does not make sense unless there is something else in your taglib or something unusual in the GSP which is invoking the tag.

Does your taglib maybe have something like defaultEncodeAs='html' in it?

like image 56
Jeff Scott Brown Avatar answered Jan 13 '23 09:01

Jeff Scott Brown