例如,当我希望<custom:footer/>
无法在一个页面上多次出现时。
答案 0 :(得分:1)
每次调用标记时,都要在页面上下文中设置一个属性。如果该属性已存在,则表示已为当前页面调用了标记,因此抛出异常。像这样(未经测试)
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
}
}