开发者

Passing Parent Element to Method from MarkupBuilder

开发者 https://www.devze.com 2023-04-04 09:39 出处:网络
I have a custom taglib in Grails and I am using MarkupBuilder to help drive some dynamic forms.I need to pull some of this form creation code out into their own classes/methods so they can be reused a

I have a custom taglib in Grails and I am using MarkupBuilder to help drive some dynamic forms. I need to pull some of this form creation code out into their own classes/methods so they can be reused and I'd like to be able to use Mar开发者_JAVA百科kupBuilder inside these other classes/methods. So I have something like...

def formContainer = new MarkupBuilder(out)
formContainer.form(...) {
  table() {
     tr() {
       td() {
          // here I want to call a method and pass a reference to td()
          generateSomeFormData(this) // but this doesn't work.
       }
     }
   }
}

In the td(), I want to call a method but I need to pass it a reference to td. 'this' doesn't seem to reference that element.

My other method might look something like (very generic to get the point across)

generateSomeFormData(parentElement) {
   parentElement.input(type:'text')
}


I believe

      generateSomeFormData( delegate )

should work

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号