freemarker

What are the main differences between StringTemplate and FreeMarker?

旧时模样 提交于 2019-12-03 08:17:04
问题 The net seems to be full of comparisons between Velocity and FreeMarker, and they seem to be reasonably equivalent. But there seems to be almost no comparisons between StringTemplate and FreeMarker! So, what are the main differences between StringTemplate and FreeMarker? My usage for them would be to generate HTML pages only. Out of the two, I would've expected FreeMarker to be the more suitable and more capable, as that seems to the more common one - but through a quick glance it seems that

Struts2 tiles org.apache.tiles.extras.complete.CompleteAutoloadTilesListener integration error

匿名 (未验证) 提交于 2019-12-03 07:50:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am following answer posted here. OGNL and wildcards working in tiles definitions with struts2-tiles-plugin? If you know the answer, would apprecite if you tell me how to use freemarker with it. If don't even than I accept the answer if you solve my problem to make the code work. Everything is same but Struts2 & Tiles plugin - 2.3.4.1 pom.xml 1.6 UTF-8 3.1.2.RELEASE 2.3.4.1 1.6.6 2.2.2 <!-- Start Extras --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> </dependency> <dependency> <groupId>javax<

Better template language needed [closed]

爱⌒轻易说出口 提交于 2019-12-03 06:59:58
Yes, I know that this has been asked before . But most of the questions were two years ago, and there's got to be a better answer today. I need a template language for rendering HTML. Requirements: Must be callable from Java. Must not be Freemarker, Velocity, or StringTemplate. We've been using Freemarker for a year, and it's too slow. It consumes 50% of our CPU cycles under load. Velocity is worse than Freemarker, and StringTemplate has got its own issues. It must consume JSON, or its Java equivalent, i.e. Maps, Lists, and primitives. I'm starting to get Node.js envy. There has been a ton of

Freemarker assign list length to local variable

大憨熊 提交于 2019-12-03 06:55:33
问题 The following freemarker code causes an exception <#assign i= it.getList().size()> <#list it.getList() as elem> <#if i==1> <li>${elem.name}</li> <#else> <li class="marked">${elem.name}</li> </#if> <#assign i = i-1> </#list> The following exception is thrown: Expected hash. it.getList() evaluated instead to freemarker.template.SimpleSequence Anyone knows why? How can i assign the length of the list to my variable i ? 回答1: I figured out, that it did not understood the syntax for the size built

Freemarker print date in template

折月煮酒 提交于 2019-12-03 06:30:32
I am trying to print the current date when the template is activated. I have read that I have to pass a new Date() Java object to the template, but I don't know how to do that or where to put it in the code. Does someone know how to pass a Java object to the template in this case? Thank you !! Actually you don't have to pass a new Date() to your template, because placing a timestamp into a template's output is quite common and therefore FreeMarker provides a special variable called .now which returns the current date and time. You can use it in your template like this: Page generated: ${.now}

Use ternary operator in freemarker?

做~自己de王妃 提交于 2019-12-03 06:28:57
问题 I just want to do something like this: <a href="${ a? 'a.htm' : 'b.htm'}"> 回答1: If you're using freemarker 2.3.23 or newer, you can use the then built-in: <a href="${a?then('a.htm','b.html')}" target="${openTarget}"> If you're using an older version of freemarker, you can use instead the string built-in: <a href="${a?string('a.htm','b.html')}" target="${openTarget}"> When applied to a boolean, the string built-in will act as a ternary operator. 回答2: This macro provides a more straightforward

Passing a List of Objects to Freemarker and then Looping

坚强是说给别人听的谎言 提交于 2019-12-03 04:16:09
I've been acquainting myself with FreeMarker, a template engine for Java. I got to the point where I am able to pass an object to the template engine through a Hash Map. That works alright. But as soon as I try to pass any sort of set of multiple objects to FreeMarker it gives me a freemarker.template.TemplateException and complains that it "Expected collection or sequence. jobs evaluated instead to freemarker.template.SimpleHash". From what I understand from reading up on this in the various resources, this is to be expected. Now, I have done much of the leg work and found a number of people

Java后端使用Freemarker导出word文档的各种细节

女生的网名这么多〃 提交于 2019-12-03 03:32:47
1.前言 最近在项目中,因客户要求,需要做一个导出成word的功能(比如月度报表等),技术选型也考虑过几种,比如easypoi,itext,但发现这两种在实现起来有困难,所以最终还是选Freemarker模板进行导出,灵活性比较好。 2.实现步骤 1.准备好标准文档的word,标题格式间距什么的先设计好,这是减少后面修改模板文很重要一步; 2.打开word原件把需要动态修改的内容替换成***,如果有图片,尽量选择较小的图片几十K左右,并调整好位置; 3.另存为,选择保存类型Word 2003 XML 文档(*.xml)【这里说一下为什么用Microsoft Office Word打开且要保存为Word 2003XML,本人亲测,用WPS找不到Word 2003XML选项,如果保存为Word XML,会有兼容问题,避免出现导出的word文档不能用Word 2003打开的问题】,还有保存的文件名尽量不要是中文; 4.用NotePad打开文件,notepad预先装好xml的插件,然后格式化,当然也可以用Firstobject free XML editor打开文件,选择Tools下的Indent【或者按快捷键F8】格式化文件内容。看个人喜欢; notepad xml插件下载地址: https://sourceforge.net/projects/npp-plugins/files/XML

Limit string length in FreeMarker

匿名 (未验证) 提交于 2019-12-03 03:05:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to get a substring from a string in FreeMarker. However there are 2 thigns to consider: The string can be null The string can be shorter then the maximum string length I do the following: <#list landingpage1.popularItems as row> <li> <span class="minititle"> <#assign minititle=(row.title!"")> <#if minititle?length < 27> ${minititle} <#else> ${minititle?substring(0,26)} ... <#/if> </span> </li> </#list> I get a freemarker error saying: Failed to load templates: Encountered "</#list>" at line 144, column 65 in landingpage1.ftl. Was

Load FreeMarker templates from database

匿名 (未验证) 提交于 2019-12-03 01:25:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I would like to store my FreeMarker templates in a database table that looks something like: template_name | template_content --------------------------------- hello |Hello ${user} goodbye |So long ${user} When a request is received for a template with a particular name, this should cause a query to be executed, which loads the relevant template content. This template content, together with the data model (the value of the 'user' variable in the examples above), should then be passed to FreeMarker. However, the FreeMarker API seems to assume