Hi Lidija, I don't use Chenillekit for Freemarker, but I integrated Freemarker not too long ago, also to render emails, using the AssetSource service:
First, I created a AssetTemplateLoader implements TemplateLoader which uses the AssetSource service behind the scenes to load the actual template from a regular Resource object. Then I created a Freemarker service with a render method. Something like this: public String render(Resource templateResource, Map dataModel) to render the text (or email) to a String. Now, you can inject your template as a Resource object into the service / page which is using the Freemarker service. Using the AssetSource also allow you to create localized template files, if necessary. Best, Thilo ________________________________________ From: Lidija Dolinar <[email protected]> Sent: Monday, May 26, 2014 15:03 To: Tapestry users Subject: FreeMarker configuration problems Hi, I'm trying to use freemarker templates according to the following instructions: http://chenillekit.codehaus.org/chenillekit-template/howto_freemarkerservice.html My code in AppModule is the same as specified above. In my Java code I'm trying to send mail with the use of a template file: OutputStream emailBodyStream = new ByteArrayOutputStream(); templateService.mergeDataWithResource(new URIResource("./templates/test.ftl"), emailBodyStream, parameterMap); mailService.sendHtmlMail(mmh, emailBodyStream.toString()); The template file is not found - I get exceptions no matter how I set the URIResource path to the template file: - If the path is "./templates/test.ftl", there's a "java.lang.IllegalArgumentException: URI is not absolute" exception in URIResource.exists() method when calling uri.toURL(). Why does this error occur? (the instructions specify relative path to the file as a parameter to the URIResource). - If the path is an absolute filepath, i.e. "file:/home/lidija/workspace/.../templates/test.ftl", there's a "java.lang.RuntimeException: Template file:/home/lidija/workspace/... not found". The file exists though and has read / write / execute permissions on it. (I'm just trying to understand, of course the path shouldn't be set like this.) - If the path is absolute filepath to the file, without the "file:" String, the eror is again "java.lang.IllegalArgumentException: URI is not absolute" My questions are: - should I specifically set the path to the "templates" folder at configuration time? - how to specify the template filename parameter to URIResource? Any suggestions welcome. Kind regards, Lidija --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
