Grails
  1. Grails
  2. GRAILS-4713

Invoking tags as methods, body is written to output immediately when called, and does not return the content of the body as a String

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2-M1
    • Component/s: None
    • Labels:
      None

      Description

      When invoking a tag as a method with a body, the body object passed to the tag is no longer the original Closure, it has been wrapped up - and when you invoke it it immediately writes to out, and returns and empty string. So it appears that:

      out << body()

      is doing the right thing but you soon see the problem if you do this:

      def b = body()
      out << "This comes first" << b

      You will see the body comes out before the string.

      Here's a concrete Taglib example from Graeme demonstrating this:

      class TestTagLib {
      
      	def test2 = { attrs, body ->
      		out << "four" << test(foo:"bar", "foo") << "five"
      	}
      	
      	def test = { attrs, body ->
      		def value = body()
      		out << "one" << value << "two"
      	}
      }
      

        Activity

        Hide
        Graeme Rocher added a comment -

        Fixed

        Show
        Graeme Rocher added a comment - Fixed

          People

          • Assignee:
            Graeme Rocher
            Reporter:
            Marc Palmer
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development