Return-Path: Delivered-To: apmail-click-dev-archive@www.apache.org Received: (qmail 94095 invoked from network); 22 Jul 2010 08:50:53 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 22 Jul 2010 08:50:53 -0000 Received: (qmail 94702 invoked by uid 500); 22 Jul 2010 08:50:53 -0000 Delivered-To: apmail-click-dev-archive@click.apache.org Received: (qmail 94648 invoked by uid 500); 22 Jul 2010 08:50:51 -0000 Mailing-List: contact dev-help@click.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@click.apache.org Delivered-To: mailing list dev@click.apache.org Received: (qmail 94641 invoked by uid 99); 22 Jul 2010 08:50:50 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Jul 2010 08:50:50 +0000 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=FREEMAIL_FROM,SPF_HELO_PASS,SPF_NEUTRAL,T_TO_NO_BRKTS_FREEMAIL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: 216.139.236.158 is neither permitted nor denied by domain of aprpda@gmail.com) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Jul 2010 08:50:44 +0000 Received: from jim.nabble.com ([192.168.236.80]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1ObrTz-0006In-Lm for dev@click.apache.org; Thu, 22 Jul 2010 01:50:23 -0700 Date: Thu, 22 Jul 2010 01:50:23 -0700 (PDT) From: AndreyRybin To: dev@click.apache.org Message-ID: <1279788623663-5324521.post@n2.nabble.com> Subject: Page.template (or similar) method and more seamless Velocity/Freemarker integration MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Just copy of http://click.1134972.n2.nabble.com/recaptcha-works-with-click-tp5296015p5324509.html http://click.1134972.n2.nabble.com/recaptcha-works-with-click-tp5296015p5324509.html === example code: return "br/>To verify that you are human
" + "When using this method to prepare a text for a mail to be sent with Spring's * mail support, consider wrapping IO/TemplateException in MailPreparationException. * @param model the model object, typically a Map that contains model names * as keys and model objects as values * @return the result as String * @throws IOException if the template wasn't found or couldn't be read * @throws TemplateException if rendering failed */ public String template (String templatePath, Map model) throws IOException, TemplateException { // Get the template object Template template = configuration.getTemplate(templatePath); StringWriter writer = new StringWriter(); try { // Merge the data-model and the template template.process(model, writer); } catch (freemarker.template.TemplateException fmte) { throw new TemplateException(fmte); } return result.toString(); }//template and also good idea to add handy functions from Google Guava to ClickUtils: public static Map mapOf (final K k, final V v) { final Map map = new LinkedHashMap(); map.put(k, v); return map; }//mapOf public static Map mapOf (final K k1, final V v1, final K k2, final V v2) { final Map map = new LinkedHashMap(); map.put(k1, v1); map.put(k2, v2); return map; }//mapOf public static Map mapOf (final K k1, final V v1, final K k2, final V v2, final K k3, final V v3) { final Map map = new LinkedHashMap(); map.put(k1, v1); map.put(k2, v2); map.put(k3, v3); return map; }//mapOf then you can make above code easy return template("/com/andreig/hiredonphone/cap.ftl_or_vm", mapOf("public_key", public_key); Template in external file (not in java String) is good thing: IDE can highlight and verify it. Only one problem here: Freemarker/Velocity binding (if you change template engine code stop working). But there is my comment in JIRA with idea how to solve it: https://issues.apache.org/jira/browse/CLK-364?focusedCommentId=12801392&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_12801392 PS: just my fast brain dump (so sorry for usual bad English) -- View this message in context: http://click.1134972.n2.nabble.com/Page-template-or-similar-method-and-more-seamless-Velocity-Freemarker-integration-tp5324521p5324521.html Sent from the click-development mailing list archive at Nabble.com.