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 MarkupBuilder 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
should work