commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Nichols <>
Subject [jelly] How to pass params to bean tags created from a BeanTagLibrary?
Date Mon, 17 Mar 2003 20:19:30 GMT

I'm having some difficulty creating Jelly-aware beans that keep track of 
thread-related data - in this case the current context. I'm trying to pass 
the context through to the beans, but I can't see how to do it. My 
CustomBeanTagLibrary has
registerBean ("sync", SyncTag.class, "execute");

I've tried overriding BeanTagLibrary.createBeanTag() - I can see the 
BeanTag that's created, but not the SyncTag. I can easily pass the context 
to my CustomBeanTagLibrary, how do I get it from there down to the SyncTag 
that's specified in the registerBean() call?

Once I have access to the context in SyncTag, I will then need to pass it 
down to the individual beans. Documentation here is a little fuzzy :) From 
the Ant docs at
it seems the simplest is
SyncTag.addFoo (FooWidget fooWidget);
This works, and invokes the no-arg FooWidget ctor ... which (surprise!) 
doesn't allow me to pass in a context.

When I instead use
FooWidget createFoo();
I can now pass any parameters I like - but I no longer get processing of 
the attributes triggering the setBar() methods before I get the newly 
created FooWidget.


The objective here (given a highly intermittent schedule to work on it!) is 
to have a top-level "action" tag - in this case "sync" - with 
children/grandchildren providing the data, and (currently) 
SyncTag.execute() doing the processing - in this case, kicking off some 
custom processing of the inputs and sending the result to an output file. 
Looks like this:
   <input1><file name="reggae.xml"/></input1>
   <input2><url value=""/></input2>
   <output><file name="punkreggae.xml"/></output>

  I have this working using TagLibrary and registerTag(), registering all 
the tags with registerTag -- but the plumbing is very rigid, adding new 
tags is a pain. The BeanTagLibrary looked a much better fit, since only the 
"sync" tag needs to take any action, and this is well handled by James' new 
invokeMethod logic.

However, I now want to have custom processing for attributes on the 
grandchildren - e.g. FileTag, <file name="reggae.xml"/> in the snippet 
above -- and I want access to the context in the FileTag.setName() method 
that gets called to process this attribute. Broadly, adding a "defid" 
attribute to the <file> tag will insert the FileTag into the context, with 
key given by defid, so that it can later be retrieved by another tag (I've 
decided against j:set for this). I'm putting this logic into 
FileTag.setName() and FileTag.setDefid().

I'm pretty sure that BeanTagLibrary is no longer such a good fit here - do 
people agree? Is it time to refactor back to a vanilla TagLibrary impl, 
relying on doTag()? The BeanTag logic is just splendid, but I think I may 
be pushing it too far here...

Thanks to all for your help so far - isn't the bleeding edge fun, eh?

Best Regards,

View raw message