commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Sell <christian.s...@netcologne.de>
Subject Re: [jelly] Taglib best practices for nested elements?
Date Thu, 23 Jan 2003 22:40:37 GMT
> Looking at jelly:bean - 
> http://jakarta.apache.org/commons/sandbox/jelly/tags.html#jelly:bean - 
> leads me to
> http://jakarta.apache.org/commons/sandbox/jelly/apidocs/org/apache/commons/jelly/tags/bean/BeanTag.html

> 
> -- is that correct? If so, there is the intriguing doc comment
> "Creates a bean for the given tag which is then either output as a 
> variable or can be added to a parent tag. "
> 
> So... **how** do I add it to the parent tag? Is there some documentation 
> on how to do this?

the docs are somewhat misleading. My finding is that the only tag from 
BeanTagLibrary that you will ever be using explicitly is <beandef/>, 
which allows you to give the root tag a class identity (aka type). For 
all nested tags, the class identity is inferred.

If you already have a root/parent tag, then all you need to do is have 
it implement the BeanSource interface and appropriate addXXX and/or 
createXXX methods for the nested elements on all level. After that, all 
nested elements (provided they are from the bean namespace), will 
silently slip into your object hierarchy.

Look into the test source for BeanTagLib (from CVS preferredly), and the 
examples we discussed in the earlier thread.

> 
> 
>> 2. inherit your TagLib from BeanTaglib
>> 3. use the BeanTagLib classes in your taglib implementation
> 
> 
> I'm not clear what this gives me over the standard TagLib - how would I 
> use the extra functionality offered by BeanTagLibrary over vanilla 
> TagLibrary? Looking at 
> http://jakarta.apache.org/commons/sandbox/jelly/apidocs/org/apache/commons/jelly/tags/bean/BeanTagLibrary.html

> , this seems to offer an ability to create new tags - but I don't need 
> to define tags within the Jelly script, I'm defining an XML syntax in 

by inheriting/using BeanTagLib, you can predefine the root tag 
programatically, and provide the rest of the functionality from within 
your own namespace.

> My second option I described as creating a new method:
> 
>> JellyUtils.tagToDom4jElement (this);
> 
>  From http://jakarta.apache.org/commons/sandbox/jelly/pipeline.html :
> "A Jelly Tag can choose how to invoke its body. So it could
> 
>     * optionally evaluate its body based on some condition
>     * loop over its body via some iteration
> * parse its body into some DOM model or turn the XML events into some 
> kind of Java objects or other kind of data structure"
> 
> How can I do this? How could I implement my specious 
> JellyUtils.tagToDom4jElement() method? Tag.getBody() returns a Script, 
> from which I haven't figured out how to get a dom4j (or other) tree.

dont know. I prefer letting Jelly do the parsing

- Christian


Mime
View raw message