Grails
  1. Grails
  2. GRAILS-8250

fieldImpl in FormTagLib doesn't wipe the attrs after using them

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3.7, 2.0-RC1
    • Fix Version/s: 2.1-RC1
    • Component/s: TagLib
    • Labels:
    • Patch Submitted:
      Yes

      Description

      My TagLib is extending FormTagLib, with the next implementation:

      def myMethod =

      { attrs, body -> attrs.name = "A" attrs.type = "text" attrs.tagName = "textField" fieldImpl(out, attrs) attrs.name = "B" attrs.type = "text" attrs.tagName = "textField" fieldImpl(out, attrs) }

      And the output is the next one:

      <input type="text" name="A" id="A" value="" />
      <input type="text" name="B" id="A" value="" />

      Obviously the Id of the second element should be "B".

      the problem is in this function in FormTagLib:

      def fieldImpl(out, attrs) {
      resolveAttributes(attrs)
      attrs.id = attrs.id ?: attrs.name
      out << "<input type=\"$

      {attrs.remove('type')}

      \" "
      outputAttributes(attrs, out)
      out << "/>"
      }

      The attrs.id is initialized with whatever comes in the attrs.name (only if attrs.id is empty), so my first call initializes the attrs.id, but in this other function:

      void outputAttributes(attrs, writer) {
      attrs.remove('tagName') // Just in case one is left
      attrs.each

      { k, v -> writer << k writer << '="' writer << v.encodeAsHTML() writer << '" ' }

      }

      Doesn't remove the attrs (and I think it should do it, isn't it?), maybe something like this:

      void outputAttributes(attrs, writer) {
      attrs.remove('tagName') // Just in case one is left
      attrs.each

      { k, v -> writer << k writer << '="' writer << attrs.remove(k).encodeAsHTML() writer << '" ' }

      }

        Issue Links

          Activity

          There are no comments yet on this issue.

            People

            • Assignee:
              Jeff Scott Brown
              Reporter:
              David Santamaria
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development