commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james_strac...@yahoo.co.uk>
Subject Re: [jelly] Using BeanTagLibrary for "action" tags
Date Mon, 03 Mar 2003 19:08:08 GMT
 From: "Thomas Nichols" <nx10mail@yahoo.co.uk>
> 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
prefixes...

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

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 = iter.next();
                ...
                // process a bean
            }
            list.clear();
        }

        // CollectionTag interface
        public void addItem(Object bean) {
            list.add(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.

James
-------
http://radio.weblogs.com/0112098/


__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Mime
View raw message