You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Andreas Bohnert <ab...@weberhofer.at> on 2009/03/16 17:45:37 UTC

Accessing the Toolbox

dear velocity forum,

I need access to a tool instance which is configured in my toolbox.xml 
from within java.
how can I access these (request-scope) instances from:

a.) ActionForward execute(ActionMapping mapping, ActionForm form, 
HttpServletRequest request, HttpServletResponse response)
     in *Action.java?


b.) another tool?
I have implemented
public void init( Object context ) and I'm getting the ViewContext, but 
when I try ChainedContext.getToolBox() it is always null!



Can you give me a hint?

Thanks,
Andreas



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


Re: Accessing the Toolbox

Posted by Andreas Bohnert <ab...@weberhofer.at>.
hi nathan,

I'm using struts 1.3.8, velocity 1.6 and velocity tools 1.4.

Thanks!
Andreas

Nathan Bubna schrieb:
> What framework are you using VelocityTools with?  What version of
> VelocityTools are you using?
>
> On Mon, Mar 16, 2009 at 9:45 AM, Andreas Bohnert <ab...@weberhofer.at> wrote:
>   
>> dear velocity forum,
>>
>> I need access to a tool instance which is configured in my toolbox.xml from
>> within java.
>> how can I access these (request-scope) instances from:
>>
>> a.) ActionForward execute(ActionMapping mapping, ActionForm form,
>> HttpServletRequest request, HttpServletResponse response)
>>    in *Action.java?
>>
>>
>> b.) another tool?
>> I have implemented
>> public void init( Object context ) and I'm getting the ViewContext, but when
>> I try ChainedContext.getToolBox() it is always null!
>>
>>
>>
>> Can you give me a hint?
>>
>> Thanks,
>> Andreas
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>   


Re: Accessing the Toolbox

Posted by Nathan Bubna <nb...@gmail.com>.
What framework are you using VelocityTools with?  What version of
VelocityTools are you using?

On Mon, Mar 16, 2009 at 9:45 AM, Andreas Bohnert <ab...@weberhofer.at> wrote:
> dear velocity forum,
>
> I need access to a tool instance which is configured in my toolbox.xml from
> within java.
> how can I access these (request-scope) instances from:
>
> a.) ActionForward execute(ActionMapping mapping, ActionForm form,
> HttpServletRequest request, HttpServletResponse response)
>    in *Action.java?
>
>
> b.) another tool?
> I have implemented
> public void init( Object context ) and I'm getting the ViewContext, but when
> I try ChainedContext.getToolBox() it is always null!
>
>
>
> Can you give me a hint?
>
> Thanks,
> Andreas
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

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


Re: Accessing the Toolbox

Posted by Claude Brisson <cl...@renegat.net>.
That's a need I encountered once with Velosurf. See:

http://velosurf.sourceforge.net/api/velosurf/util/ToolFinder.html

(you can grab the corresponding source from the velosurf tarball).

It lets you find one tool by its class, using the method:

static <T> T findSessionTool(javax.servlet.http.HttpSession session,
java.lang.Class<T> toolClass)

but it only works with session tools.


  Claude

On mar, 2009-03-17 at 23:20 +0100, Andreas Bohnert wrote:
> thank you nethan, this is very helpful!
> unfortunately I have to stay with VelocityTools 1.x as long as there is 
> no 2.0 release candiate.
> 
> best regards,
> andreas
> >> dear velocity forum,
> >>
> >> I need access to a tool instance which is configured in my toolbox.xml from
> >> within java.
> >> how can I access these (request-scope) instances from:
> >>
> >> a.) ActionForward execute(ActionMapping mapping, ActionForm form,
> >> HttpServletRequest request, HttpServletResponse response)
> >>    in *Action.java?
> >>     
> >
> > There's no easy way in VelocityTools 1.x.   You'll probably have to
> > extend the VelocityViewServlet and override the fillContext(context,
> > request) method, and grab either the whole toolbox or just the tools
> > you need and put them in the request attributes there.
> >
> > In VelocityTools 2, the toolbox is stored in the request attributes by
> > default (rather than a field in the context class), so you just pull
> > out the toolbox and ask it for a tool.
> >
> >   
> >> b.) another tool?
> >> I have implemented
> >> public void init( Object context ) and I'm getting the ViewContext, but when
> >> I try ChainedContext.getToolBox() it is always null!
> >>     
> >
> > That's because init happens while the toolbox is being created, which
> > is before it is made available to the ChainedContext.  If you just
> > keep the ChainedContext and ask it for the toolbox later, that should
> > work.
> >
> >   
> >> Can you give me a hint?
> >>
> >> Thanks,
> >> Andreas
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> >> For additional commands, e-mail: user-help@velocity.apache.org
> >>
> >>
> >>     
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > For additional commands, e-mail: user-help@velocity.apache.org
> >
> >   
> 


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


Re: Accessing the Toolbox

Posted by Andreas Bohnert <ab...@weberhofer.at>.
thank you nethan, this is very helpful!
unfortunately I have to stay with VelocityTools 1.x as long as there is 
no 2.0 release candiate.

best regards,
andreas
>> dear velocity forum,
>>
>> I need access to a tool instance which is configured in my toolbox.xml from
>> within java.
>> how can I access these (request-scope) instances from:
>>
>> a.) ActionForward execute(ActionMapping mapping, ActionForm form,
>> HttpServletRequest request, HttpServletResponse response)
>>    in *Action.java?
>>     
>
> There's no easy way in VelocityTools 1.x.   You'll probably have to
> extend the VelocityViewServlet and override the fillContext(context,
> request) method, and grab either the whole toolbox or just the tools
> you need and put them in the request attributes there.
>
> In VelocityTools 2, the toolbox is stored in the request attributes by
> default (rather than a field in the context class), so you just pull
> out the toolbox and ask it for a tool.
>
>   
>> b.) another tool?
>> I have implemented
>> public void init( Object context ) and I'm getting the ViewContext, but when
>> I try ChainedContext.getToolBox() it is always null!
>>     
>
> That's because init happens while the toolbox is being created, which
> is before it is made available to the ChainedContext.  If you just
> keep the ChainedContext and ask it for the toolbox later, that should
> work.
>
>   
>> Can you give me a hint?
>>
>> Thanks,
>> Andreas
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>   


Re: Accessing the Toolbox

Posted by Nathan Bubna <nb...@gmail.com>.
On Mon, Mar 16, 2009 at 9:45 AM, Andreas Bohnert <ab...@weberhofer.at> wrote:
> dear velocity forum,
>
> I need access to a tool instance which is configured in my toolbox.xml from
> within java.
> how can I access these (request-scope) instances from:
>
> a.) ActionForward execute(ActionMapping mapping, ActionForm form,
> HttpServletRequest request, HttpServletResponse response)
>    in *Action.java?

There's no easy way in VelocityTools 1.x.   You'll probably have to
extend the VelocityViewServlet and override the fillContext(context,
request) method, and grab either the whole toolbox or just the tools
you need and put them in the request attributes there.

In VelocityTools 2, the toolbox is stored in the request attributes by
default (rather than a field in the context class), so you just pull
out the toolbox and ask it for a tool.

>
> b.) another tool?
> I have implemented
> public void init( Object context ) and I'm getting the ViewContext, but when
> I try ChainedContext.getToolBox() it is always null!

That's because init happens while the toolbox is being created, which
is before it is made available to the ChainedContext.  If you just
keep the ChainedContext and ask it for the toolbox later, that should
work.

>
>
> Can you give me a hint?
>
> Thanks,
> Andreas
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

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