velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Bubna <nbu...@gmail.com>
Subject Re: Struts and I18N
Date Thu, 25 Aug 2005 16:47:52 GMT
On 8/25/05, Neal Smith <Neal.Smith@sas.com> wrote:
> Hi Nathan,
> 
>   Thanks for the reply.
> 
>   I have looked at the examples and they are fine for syntax of the API, but I think
I've got 
> more of an issue with how the emails are being generated, like you mention below.

agreed.

>   I have another quick question.  In the rest of the application, I'm using JSTL fmt
library tags to format dates, currency, etc. for I18N.  I don't think I'm going to be able
to do that with Velocity, correct?

actually, you can do this with VelocityTools.  we have both a DateTool
and a NumberTool that should support I18N just fine. 
http://jakarta.apache.org/velocity/tools/generic/

> 
>   Disclaimer:  I didn't come up with this scheme!  :)
> 
>   We have a JSP where we show the user some boilerplate email text, allow them to manipulate
it and the email subject, specify an email address and then they submit this.
> 
>   Within the struts action class we call into a struts service to send the email.  That
method creates a couple of VelocityContexts (two different template files are used), that
represent email attachments.  This is all packaged up using MimeMultipart to create the message
that we then send via javax.mail.Transport.
> 
>   Here is the service init method where the VelocityEngine is initialized:
> 
> public void init(Properties initProperties)
>            throws ServiceException
>         {
#snip
>                 InputStream is = this.getClass().getResourceAsStream(VELOCITY_PROPERTIES_FILE);
>                 Properties velocityProperties = new Properties();
>                 _velocityEngine = new VelocityEngine();
> 
>                 try
>                 {
>                         velocityProperties.load(is);
>                 }
>                 catch (IOException ioe)
>                 {
>                         throw new ServiceException("Unable to load Velocity properties
file: "
>                                                    + VELOCITY_PROPERTIES_FILE, ioe);
>                 }
> 
>                 try
>                 {
>                         _velocityEngine.init(velocityProperties);
>                 }
>                 catch (Exception e)
>                 {
>                         throw new ServiceException("Unable to initialize Velocity engine.",
e);
>                 }
#snip

that looks fine, i think.

>   Here is the method where we are "generating" the template:
> 
> private File createFile(String prefix, String template, VelocityContext context)
>            throws ServiceException
>         {
#snip

ok, but where are you getting the VelocityContext from?  if you want
access to a working and initialized MessageTool then you'll want to
get the context created by the VelocityViewServlet.  which, by the
way, are you using in the course of the servlet request that calls the
methods above?

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


Mime
View raw message