You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Thomas Nichols <nx...@yahoo.co.uk> on 2003/03/17 21:19:30 UTC

[jelly] How to pass params to bean tags created from a BeanTagLibrary?

Hi,

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
  http://ant.apache.org/manual/develop.html#nested-elements
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:
<sync>
   <input1><file name="reggae.xml"/></input1>
   <input2><url value="http://www.pinkflag.com/wire/punk.xml"/></input2>
   <output><file name="punkreggae.xml"/></output>
</sync>

  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,
Thomas.


Re: [jelly] How to pass params to bean tags created from a BeanTagLibrary?

Posted by Thomas Nichols <nx...@yahoo.co.uk>.
Hah! 5 minutes after posting I found the typo that was stopping createFoo 
invoking setName...

I'd still love to know whether others consider this a suitable use case for 
BeanTagLibrary, though.
Thanks,
Thomas (talking to himself again...)


At 20:19 17/03/2003 +0000, Thomas Nichols wrote:
>Hi,
>
>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
>  http://ant.apache.org/manual/develop.html#nested-elements
>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:
><sync>
>   <input1><file name="reggae.xml"/></input1>
>   <input2><url value="http://www.pinkflag.com/wire/punk.xml"/></input2>
>   <output><file name="punkreggae.xml"/></output>
></sync>
>
>  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,
>Thomas.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org