On Mon, Mar 16, 2009 at 9:45 AM, Andreas Bohnert <[email protected]> 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: [email protected] > For additional commands, e-mail: [email protected] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
