开发者

How can I restrict custom taglib tag apperence to one per page?

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
   }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜