문제

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...

도움이 되었습니까?

해결책

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?

다른 팁

Use the tag like this:

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

HTML5 can render <br>, but it seems you are using version 4 or lower.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top