You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2007/11/01 21:37:54 UTC

[veltools] Toolbox parameters

All,

Any given tool gets an init(Object) call before it gets used. For "view"
tools, that object is a ViewContext. How can I pass configuration
parameters from the toolbox.xml file into the tools via the ViewContext
object?

It looks like the only attribute really used is the XHTML one, but
that's not tied to a tool -- it's tied to all tools, so it lives as an
attribute of the ViewContext.

I'd like to add a configuration parameter to the LinkTool, but I can't
seem to figure out if there's an existing mechanism to get parameters
from the toolbox.xml file into the actual tool during initialization.

Any tips?

Thanks,
-chris


Re: [veltools] Toolbox parameters

Posted by Nathan Bubna <nb...@gmail.com>.
On 11/1/07, Christopher Schultz <ch...@christopherschultz.net> wrote:
> Nathan,
>
> Nathan Bubna wrote:
> > For Veltools 1.x, in the tool:
> >
> > public void configure(Map params) {
> >    //TODO: extract and use params here
> > }
>
> I'm an idiot. I totally missed that method and focused all my
> concentration on the init() method instead.

momentarily blind != idiot  :)

> Is there any particular reason that these two methods aren't a single
> method instead?

in 1.x, only reason is backwards compatibility
in 2.x, init() is supported but deprecated; it's all about configure()
or individual setters now!

> Thanks,
> -chris
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


Re: [veltools] Toolbox parameters

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Nathan,

Nathan Bubna wrote:
> For Veltools 1.x, in the tool:
> 
> public void configure(Map params) {
>    //TODO: extract and use params here
> }

I'm an idiot. I totally missed that method and focused all my
concentration on the init() method instead.

Is there any particular reason that these two methods aren't a single
method instead?

Thanks,
-chris


Re: [veltools] Toolbox parameters

Posted by Nathan Bubna <nb...@gmail.com>.
On 11/1/07, Christopher Schultz <ch...@christopherschultz.net> wrote:
> All,
>
> Any given tool gets an init(Object) call before it gets used. For "view"
> tools, that object is a ViewContext. How can I pass configuration
> parameters from the toolbox.xml file into the tools via the ViewContext
> object?

For Veltools 1.x, in the tool:

public void configure(Map params) {
   //TODO: extract and use params here
}

and in the toolbox.xml:

<parameter name="name" value="value"/>

LinkTool already has a configure() method to set the self-absolute and
self-include-parameters properties.

In Veltools 2.x, you can still use configure(Map) or you can have
individual setters in the tool:

public void setMyProperty(Boolean property) {
   //deal with the property
}

and in the tools.xml:
<tool class="org.foo.MyClass" myProperty="true"/>

or

<tool class="org.foo.MyClass">
    <property name="myProperty" value="true"/>
    <property name="otherProp">This is "crazy"!</property>
</tool>

lots of options.  :)

> It looks like the only attribute really used is the XHTML one, but
> that's not tied to a tool -- it's tied to all tools, so it lives as an
> attribute of the ViewContext.
>
> I'd like to add a configuration parameter to the LinkTool, but I can't
> seem to figure out if there's an existing mechanism to get parameters
> from the toolbox.xml file into the actual tool during initialization.
>
> Any tips?
>
> Thanks,
> -chris
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org