You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Vishal Veda <vv...@sbcglobal.net> on 2003/07/09 18:53:28 UTC

Using Velocity tools in an application?

Hi,

I'm using the Velocity Struts toolset in a web application (Tomcat 4.1.18).
However, a few parts of my application requires using a VelocityEngine
instance.

Has anyone used the Velocity Struts toolset with VelocityEngine? I need
access to the MessageTool and LinkTool (to get to Struts actionmappings). (I
have access to the ServletContext - but not to Request and Response
objects - since this is offline processing).

(I understand I could use the java.util package directly - but I'm looking
to promote consistency with other velocity templates that use the tools)

Has anyone tried to use the above mentioned tools in an application mode?
Any pointers are appreciated.

Cheers,

- Vishal.


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


Re: Using Velocity tools in an application?

Posted by Nathan Bubna <na...@esha.com>.
Vishal Veda said:
...
> Has anyone used the Velocity Struts toolset with VelocityEngine? I need
> access to the MessageTool and LinkTool (to get to Struts actionmappings). (I
> have access to the ServletContext - but not to Request and Response
> objects - since this is offline processing).

hmm.  i don't think you'll be able to use LinkTool or StrutsLinkTool without
Request and Response objects.  you'll need to either find a way to get a
request and response to work with (dummy ones maybe?) or else you'll have to
just copy/modify the relevant StrutsUtils and LinkTool code into some sort of
OfflineStrutsLinkTool.

but i think you would be ok using the MessageTool with just access to the
ServletContext.  you'll have to create your own implementation of the
ViewContext interface that will return the ServletContext (for MessageTool it
can return null for the other methods).  then just create an instance of
MessageTool and pass your ViewContext to the init(Object) method.  however, i
should note that without access to a request, the MessageTool will not be
Locale-sensitive.  you would need to extend MessageTool and override
init(Object) to set the Locale you desire there somehow.

> (I understand I could use the java.util package directly - but I'm looking
> to promote consistency with other velocity templates that use the tools)

yeah, consistency is good.

> Has anyone tried to use the above mentioned tools in an application mode?
> Any pointers are appreciated.

i haven't, and i'll bet that you're the first.  these tools are specifically
designed and intended for request-based use.  thus, trying to use them without
a request is quite unorthodox.  :)

Nathan Bubna
nathan@esha.com


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