class TagLibAdapter
extends Object
Adapts Grails taglibs for use in the template engine. An adapter may be created like this:
def model = [:]
def tpl = template.make(model)
model.g = new TagLibAdapter(tpl)
model.g.registerTagLib(SimpleTagLib)
where SimpleTagLib is:
class SimpleTagLib {
def emoticon = { attrs, body ->
out << body() << (attrs.happy == 'true' ? " :-)" : " :-(")
}
}
Then it can be used inside a template like this:
g.emoticon(happy:'true') { 'Hi John' }
Performance-wise, it would be better to reimplement the taglib,
but this makes it easier to reuse existing code.
| Constructor and description |
|---|
TagLibAdapter(BaseTemplate tpl)Creates an adapter bound to the supplied template instance. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
Object |
methodMissing(String name, Object args)Dispatches an unknown method call to the first registered tag library exposing a matching closure property. |
|
void |
registerTagLib(Class tagLibClass)Instantiates and registers a tag library class. |
|
void |
registerTagLib(Object tagLib)Registers an already-instantiated tag library object. |
Creates an adapter bound to the supplied template instance.
tpl - template used to rehydrate invoked tag closuresDispatches an unknown method call to the first registered tag library exposing a matching closure property.
name - tag name requested by the templateargs - arguments forwarded to the matching tag closureInstantiates and registers a tag library class.
tagLibClass - tag library type whose no-arg constructor should be invokedRegisters an already-instantiated tag library object.
tagLib - tag library instance to make available to templatesCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.