6.2.2.6 标签的方法调用 - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith
Version: null
6.2.2.6 标签的方法调用
One major different between GSP tags and other tagging technologies is that GSP tags can be called as either regular tags or as method calls from controllers, tag libraries or GSP views.This is particularly useful for using a tag within an attribute:In view technologies that don't support this feature you have to nest tags within tags, which becomes messy quickly and often has an adverse effect of WYSWIG tools such as Dreamweaver that attempt to render the mark-up as it is not well-formed:
One major different between GSP tags and other tagging technologies is that GSP tags can be called as either regular tags or as method calls from controllers, tag libraries or GSP views.Tags as method calls from GSPs
Tags return their results as a String-like object (aStreamCharBuffer which has all of the same methods as String) instead of writing directly to the response when called as methods. For example:Static Resource: ${createLinkTo(dir: "images", file: "logo.jpg")}<img src="${createLinkTo(dir: 'images', file: 'logo.jpg')}" /><img src="<g:createLinkTo dir="images" file="logo.jpg" />" />在GSP中以方法调用标签
当标签以方法的方式调用时,其返回一个类似String(一个StreamCharBuffer,有着跟String完全相同的方法)的对象,而不是直接写回到响应器。比如:Static Resource: ${createLinkTo(dir: "images", file: "logo.jpg")}<img src="${createLinkTo(dir: 'images', file: 'logo.jpg')}" /><img src="<g:createLinkTo dir="images" file="logo.jpg" />" />Tags as method calls from Controllers and Tag Libraries
You can also invoke tags from controllers and tag libraries. Tags within the defaultg: namespace can be invoked without the prefix and a StreamCharBuffer result is returned:def imageLocation = createLinkTo(dir:"images", file:"logo.jpg").toString()
def imageLocation = g.createLinkTo(dir:"images", file:"logo.jpg").toString()
def editor = fckeditor.editor(name: "text", width: "100%", height: "400")
在控制器和标签库中的以方法调用标签
你可以可以在控制器和标签库中调用标签。命名空间是g:的标签调用可以忽略其前缀,并且一个StreamCharBuffer类型的结果被返回:def imageLocation = createLinkTo(dir:"images", file:"logo.jpg").toString()
def imageLocation = g.createLinkTo(dir:"images", file:"logo.jpg").toString()
def editor = fckeditor.editor(name: "text", width: "100%", height: "400")

