commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <>
Subject Re: [jelly] Using BeanTagLibrary for "action" tags
Date Mon, 03 Mar 2003 19:08:08 GMT
 From: "Thomas Nichols" <>
> I'm not sure I yet understand fully how BeanTagLibrary works. Within the
> root (level0) "j:jelly" tag I want to have a sequence of level1
> "action"  tags (e.g. "blah:sync") and beneath each of those a
> "data-assembly" hierarchy of beans. Astonishingly, this actually works:
> <j:jelly xmlns:j.... xmlns:bean... xmlns:blah... >
>    <bean:sync>
>      <bean:customer ...>
>        <bean:order>
>          <bean:product .../>
>        </bean:order>
>      ...
>      </bean:customer>
>      ...
>    </bean:sync>
> </j:jelly>

BTW you can always use the default namespace to avoid typing too many

<j:jelly xmlns:j="jelly:core" xmlns="jelly:com.acme.MyTagLibrary">

If you ever want to process beans in a generic way via the BeanTagLibrary
you can write a Tag which implements the CollectionTag interface which is a
little like Ant's TaskContainer (indeed calling it ContainerTag would have
been a good idea).

e.g. if your <sync> tag wanted to process any old bean then (rather than
having specific adder or setter methods for each type of bean) then you
could do something like this...

    public class SyncTag extends TagSupport implements CollectionTag {
        private List list = new ArrayList();

        // Tag interface
        public void doTag() throws JellyTagException {
            for (Iterator iter = list.iterator(); iter.hasNext(); ) {
                Objec bean =;
                // process a bean

        // CollectionTag interface
        public void addItem(Object bean) {

I've just added a new JellyUnit test case,  testCollectionTag, to the bean
tag library that tests this behaviour and doubles up as a little demo of how
to do this.


Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts

View raw message