velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marino A. Jonsson" <marino_jons...@hotmail.com>
Subject Re: [velocity-layout] getTemplate for e-mail
Date Wed, 07 Jan 2004 19:55:43 GMT
If you want to be able to use two bundles for a single module, you have to
choose which of those two should be the default and which one should be
named.  Then you specify both bundles in the struts-config for the relevant
module like so:

<message-resources null="false" parameter="default-resources" />
<message-resources key="name-of-your-bundle" null="false"
parameter="non-default-resources" />

(where you, of course, substitute key and parameters with a key of your
choice and the names of your app-resources files).

Then you use $msg.get("links.usercode.displayName", "name-of-your-bundle")
to access resources in the non-default bundle :)

cheers,
Marinů

"IvŠn Escobedo" <iescobedo@nacion.co.cr> wrote in message
news:A2BACDFD66434F44B34E29D04DD3824126B035@S_Correo.ln.corp.nacion.com...
My friends, how are ya?

I am developing a modular struts application, so I have two
struts-configXXX.xml, two validationXXX.xml, etc, hence I have two
applicationresourcesXXX.properties.

my question is:  how to tell velocity that there's another
applicationresourcesXXX.properties?

When I use $msg.get("links.usercode.displayName") and this string is not on
the default struts-config.xml, then it doesn't work


thanks

-----Mensaje original-----
De: Mike Kienenberger [mailto:mkienenb@alaska.net]
Enviado el: Martes, 18 de Noviembre de 2003 02:55 p.m.
Para: charlieh@alloy.com; Velocity Users List
CC: charlieh@alloy.com
Asunto: Re: [velocity-layout] getTemplate for e-mail

"Charles N. Harvey III" <charlieh@alloy.com> wrote:
> Hello.
> I am using the VelocityLayoutServlet with Struts in an application
> and so far so good.  Been going along great for quite a few months
> now.
>
> I have to have my action class send out an e-mail and I want the e-mail
> formatted in a certain manner.  I have a email.vm file in my path, so
> how do i get it and then insert values like $userName into the template
> and then send it?
>
> I'm sure this is possible (and probably quite easy), I just haven't
> quite figured out how to do it.


What I use isn't much different from iescobedo@nacion.co.cr's solution -- 
it's just organized a little more differently (easier to reuse) and has some
commented-out code that could be uncommented to use the commons word-wrapper
class.

Example calling code:
===============================
Context context = new VelocityContext();
context.put("applicationName",
GlobalParameterManager.getInstance().getApplicationName());
context.put("activationCode", randomCode);
context.put("user", aUser);
context.put("userID", aUser.getUserName());
context.put("oldEmailAddress", aUser.getEmailAddress());
if (null != newEmailAddress)
{
context.put("DidEmailAddressChange", "true");
context.put("newEmailAddress", newEmailAddress);
}

String body;
try
{
body =
createMessageBody(
administrativeUser, selectedUser,
CUSTOMER_EMAIL_TEMPLATE_DIRECTORY + "SendActivationCode.vm",
context);
}
catch (ChainedException aChainedException)
{
// add your error handling here
}
===============================


===============================
private String createMessageBody(String aTemplateName, Context aContext)
throws ChainedException
{
StringWriter writer = new StringWriter();
try
{
Velocity.mergeTemplate(aTemplateName, "ISO8859-1", aContext, writer);
}
catch (ResourceNotFoundException aResourceNotFoundException)
{
ChainedException newChainedException = new
ChainedException(aResourceNotFoundException, "Unable to load email template
" + aTemplateName);

NotificationManager.getInstance().reportProgrammingError(newChainedException
);
throw newChainedException;
}
catch (ParseErrorException aParseErrorException)
{
ChainedException newChainedException = new
ChainedException(aParseErrorException, "Unable to parse email template " +
aTemplateName);

NotificationManager.getInstance().reportProgrammingError(newChainedException
);
throw newChainedException;
}
catch (MethodInvocationException aMethodInvocationException)
{
ChainedException newChainedException = new
ChainedException(aMethodInvocationException, "Unable to parse email template
" + aTemplateName);

NotificationManager.getInstance().reportProgrammingError(newChainedException
);
throw newChainedException;
}
catch (Exception anException)
{
ChainedException newChainedException = new ChainedException(anException,
"Unable to parse email template " + aTemplateName);

NotificationManager.getInstance().reportProgrammingError(newChainedException
);
throw newChainedException;
}

String body = writer.toString();

// int wordWrap = 0;
// // If the caller desires word-wrapping, do it here
// if (wordWrap > 0)
// body = WordWrapper.wrapText(body, System.getProperty("line.separator"),
wordWrap);

return body;
}
===============================

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




---------------------------------------------------------------------
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