|
From: Rob H. <ro...@ca...> - 2004-07-21 13:33:57
|
Okay, I see what you are saying. It does seem as though this can't be improved that much. I think the issue here is that this approach needs = to be covered in the docs, or maybe a blog entry. I don't mind putting = something together - I will also add this to this my book... ... which leads me nicely on to asking if anyone in the team wants to do = the tech review on the Spring book that a colleague and I are in the process = of writing. Rob -----Original Message----- From: spr...@li... [mailto:spr...@li...] On Behalf = Of j=FCrgen h=F6ller [werk3AT] Sent: 21 July 2004 14:22 To: spr...@li... Subject: Re: [Springframework-developer] E-Mail Templating Support I'm by no means against making this even easier :-) I just don't see = much potential beyond what's already there, at least if just concerning mail = body text... The current best practice is to use Spring's VelocityEngineFactoryBean = to set up a shared VelocityEngine instance, passing it to application = objects as bean reference into a setVelocityEngine setter. Those application = objects will also receive an instance of Spring's MailSender interface if they = want to send emails. Using VelocityEngineUtils is then very straightforward. FreeMarker is similar: Use a FreeMarkerConfigurationFactoryBean to set = up a shared FreeMarker Configuration instance, for bean references. Use FreeMarkerTemplateUtils' processTemplateIntoString to render the = template into a String, to be used as mail text again. The nice thing here is that the mail support does not know anything = about templating; neither the other way round. To make them work in = combination, you just generate a String via templating and pass it into a mail = message as text. And the setting up of shared engine instances leverages Spring's common IoC infrastructure, without special mechanisms. Juergen -----Original Message----- From: spr...@li... [mailto:spr...@li...]On Behalf Of Rob Harrop Sent: Wednesday, July 21, 2004 3:09 PM To: spr...@li... Subject: RE: [Springframework-developer] E-Mail Templating Support Well that is easy, but you need to create and configure an instance of VelocityEngine before you can use that, and that may lead to the bad practice of creating and initializing a new instance once per message. = It would be a trivial job to abstract all this away, plus then we could add support for other templating engines. Rob -----Original Message----- From: spr...@li... [mailto:spr...@li...] On Behalf = Of j=FCrgen h=F6ller [werk3AT] Sent: 21 July 2004 13:40 To: spr...@li... Subject: Re: [Springframework-developer] E-Mail Templating Support That's already pretty easy: You can generate the email text with the "mergeTemplateIntoString" of Spring's VelocityTemplateUtils helper, and = pass the result String into SimpleMailMessage's or MimeMessageHelper's = setText methods. 1 line to render the template (passing in a model Map), 1 line = to use it as email text for a given message. Juergen -----Original Message----- From: spr...@li... [mailto:spr...@li...]On Behalf Of Colin Sampaleanu Sent: Wednesday, July 21, 2004 1:36 PM To: spr...@li... Subject: Re: [Springframework-developer] E-Mail Templating Support It seems like a good number of the relatively complex j2ee apps=20 eventually end up rolling their own version of something like this (I=20 know we did at one of my last gigs, although that was before spring), so = if you can come up with a decent abstraction this would be worthwhile. Rob Harrop wrote: > I have been thinking of adding templated e-mail support to the mail=20 > package in Spring. In this way you can create the body of the mail as=20 > a Velocity template, and have data passed into the mail at runtime to=20 > customize it. I need to think a little more about how this would be=20 > implemented but I think the idea is sound. What does everyone else = think? > > =20 > > Rob > ------------------------------------------------------- This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools! Get your free copy of BEA WebLogic Workshop 8.1 today. http://ads.osdn.com/?ad_id=3D4721&alloc_id=3D10040&op=3Dclick _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer ------------------------------------------------------- This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools! Get your free copy of BEA WebLogic Workshop 8.1 today. http://ads.osdn.com/?ad_idG21&alloc_id=10040&op=3Dick _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer ------------------------------------------------------- This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools! Get your free copy of BEA WebLogic Workshop 8.1 today. http://ads.osdn.com/?ad_idG21&alloc_id=10040&op=3Dick _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer ------------------------------------------------------- This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools! Get your free copy of BEA WebLogic Workshop 8.1 today. http://ads.osdn.com/?ad_idG21&alloc_id=10040&op=3Dick _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer |