freemarker

Use a single freemarker template to display tables of arbitrary pojos

强颜欢笑 提交于 2019-12-08 21:25:09
问题 Attention advanced Freemarker gurus: I want to use a single freemarker template to be able to output tables of arbitrary pojos, with the columns to display defined separately than the data. The problem is that I can't figure out how to get a handle to a function on a pojo at runtime, and then have freemarker invoke that function (lambda style). From skimming the docs it seems that Freemarker supports functional programming, but I can't seem to forumulate the proper incantation. I whipped up a

Adding Spring Security JspTagLib to a Freemarker template - issues with controller unit tests

怎甘沉沦 提交于 2019-12-08 17:56:09
问题 I have added Springs jsp security taglib to a freemarker template because I'm using freemarker for the view of my web app rather than jsps. For anyone searching for how to set this up, I found Adding spring library for usage of JSP Taglibs for security in Freemarker to be a very helpful question. In summary, add the following to the *.ftl file you wish to use the tags in: <#assign security=JspTaglibs["http://www.springframework.org/security/tags"] /> Then assuming you're using maven add the

FreeMarker encoding confusion

主宰稳场 提交于 2019-12-08 17:43:55
问题 When I read an UTF-8 encoded template with FreeMarker, special chars are rendered correctly in the browser, although freeMarkerConfig.getDefaultEncoding() returns "Cp1252". If I set freeMarkerConfig.setDefaultEncoding("UTF-8") , I see only question marks in the browser, although "UTF-8" is the actual encoding of the template file. In every case the http header "Content-Type: text/html; charset=UTF-8" is sent. Any idea what is wrong? 回答1: Set the content type property into the

Use Java Properties in Freemarker

99封情书 提交于 2019-12-08 17:19:14
问题 HI, I have a typical messages.properties file in my application. I'm trying to generate an email using Freemarker. The Freemarker template should generate to a String , after which I'll send the String to the user via email. However, we need it multilingual. So Properties came to mind. My properties file looks like this: mail.layout.contactus=Contacteer ons mail.layout.greeting=Hoi In Java, I enter the Properties file in my HashMap like this: rootMap.put("lang", (mail.getLanguage().equals

Replace new line character in freemarker

守給你的承諾、 提交于 2019-12-08 16:14:05
问题 Is there any way to replace the new line character on free marker? I am trying this: <#assign str = str?replace("(\r\n)+", "</p><p>")> wich worked on java, but not in freemarker. How can I do this? Thanks in advance. 回答1: Ok, I found the problem. The replace function needs to know if the expresion is a regex, so I had to add 'r' as a parameter <#assign str = str?replace("(\r\n)+", "</p><p>",'r')> 来源: https://stackoverflow.com/questions/16108107/replace-new-line-character-in-freemarker

How to set null to a variable in freemarker

梦想与她 提交于 2019-12-08 16:05:32
问题 I can't find anything related to this on any question, and it is something really basic, but I can't figure it out. So my problem is that I don't know how to set null to a variable in freemarker. Example: ${hi!"bye"} <#-- Prints "bye" because hi is undefined --> <#assign hi="hi"> <#-- Sets a value to the var hi --> ${hi!"bye"} <#-- Prints "hi" because hi has a value --> <#assign hi=null> <#-- This does not work but is what I am looking for --> ${hi!"bye"} <#-- I want it to print "bye" because

Spring boot hot deployment for templates and resources under IntelliJ

我是研究僧i 提交于 2019-12-08 15:51:47
问题 Is anyone aware of a mechanism to get hot deployment for resources and template working under IntelliJ 14.0.2 for a Spring Boot application. I know that full Spring Boot support is scheduled for 14.1 but I have a project that I converted over from a standard WAR project to a Spring Boot project and I really miss the hot deployment. At the moment I have to manually build the project that the resources are in to get hot deployment and even then it is a bit flaky sometimes. I would prefer to

Is there any way to url decode variable on Freemarker?

孤街醉人 提交于 2019-12-08 11:21:02
问题 I'm looking for a way to url decode a string variable on Freemarker. For example, consider the following string: attr=hello+world%3F . Expected result: hello world? Any simple way to get this result? somewhat like ${attr?urlDecode}? I could not find anything online. Thanks. 回答1: As mentioned above, FreeMarker only has built in support for URL encoding, not decoding. You can however solve this by creating your own directive for URI-decoding. Something like this: https://gist.github.com/lazee

Using freemarker to generate html to send within an e-mail, is their anyway to use a rendered jsp page instead?

独自空忆成欢 提交于 2019-12-08 09:05:08
问题 The e-mail is being sent using Spring and java mail sender. Is their anyway I can use a normal jsp view and jstl tags - I don't want to learn another bunch of tags/syntax ? Currently my code looks like this : StringBuffer content = new StringBuffer(); Configuration configuration = freeMarkerConfigurer.getConfiguration(); String templateName = "vslEmail.ftl"; Map<String, String> templateVars = new HashMap<String, String>(); templateVars.put("firstName", "john"); templateVars.put("surname",

Freemarker URL Template Loader

微笑、不失礼 提交于 2019-12-08 07:50:22
问题 I would like to load Freemarker templates from one or more URLs so I subclassed the URLTemplate loader class and overrode the getURL(..) method to return the target URL (see below). I then added a couple of instances of this class to a multi template loader and added that to the Freemarker config. This works fine when the first URL returns a template but when it doesn't none of the other template loaders are called. What have I done wrong? I'm using v2.3 of Freemarker via the Restlet