For example when i want <custo开发者_如何转开发m:footer/>
to be impossible to appear multiple times on one page.
Every time the tag is called, set an attribute in the page context. If the attribute is already present, that means the tag has already been called for the current page, so throw an exception. Something like this (untested)
class MyTagLib {
def doIt = { attrs, body ->
if (pageScope.invoked) {
// throwTagError is a built-in method that is available in all tag libs
thowTagError "this tag can only be invoked once per page"
}
pageScope.invoked = true
// Now cure world poverty or whatever it is that your tag is supposed to do
}
}
精彩评论