天道酬勤,学无止境

freemarker

java.lang.NoSuchFieldError: VERSION_2_3_0

问题 I just upgraded my Struts2 version to 2.5.2 and started getting errors. My application doesn't even startup. I've made changes on the pom.xml and web.xml. I am not sure if I am missing any class but the log doesn't say that. pom.xml: <properties> <struts.version.no>2.5.2</struts.version.no> <tiles.version.no>3.0.5</tiles.version.no> </properties> <dependency> <groupId>ognl</groupId> <artifactId>ognl</artifactId> <version>3.1.8</version> </dependency> web.xml: <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter <

2022-05-15 00:12:03    分类:技术分享    java   maven   struts2   freemarker

Freemarker: call a static util method from a template file (*.ftl)

问题 在 Freemarker FTL 文件中,我想调用StringUtils.capatilize(myString) 。 例如: <p>You selected ${selectionString}.</p> <p>${StringUtils.capatilize(selectionString)} is great.</p> 我可以以某种方式导入org.apache.commons.lang3.StringUtils吗? 回答1 首先,将这些代码添加到您的Controller中: BeansWrapper wrapper = new BeansWrapper(new Version(2,3,27)); TemplateModel statics = wrapper.getStaticModels(); model.addAttribute("statics", statics); 然后,在您的.ftl文件中,像这样定义类: <#assign YourUtilClass=statics['com.springboot.util.YourUtilClass']> (包含在['']中的路径是类'路径) 最后,您可以像这样访问您的静态方法: ${YourUtilClass.yourMethod(someParams)} 回答2 您不能#import一个类,只能是其他模板。 请注意

2022-05-14 20:22:10    分类:技术分享    freemarker

Limit string length in FreeMarker

问题 我正在尝试从 FreeMarker 中的字符串中获取子字符串。 但是有 2 点需要考虑: 字符串可以为空字符串可以短于最大字符串长度 我执行以下操作: <#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> 我收到一个 freemarker 错误说: Failed to load templates: Encountered "</#list>" at line 144, column 65 in landingpage1.ftl. Was expecting one of: <ATTEMPT> ... <IF> ... <LIST> ... <FOREACH> ... <SWITCH> ... <ASSIGN> ... <GLOBALASSIGN> ... <LOCALASSIGN> ... <INCLUDE> ... <IMPORT> ... <FUNCTION> ... <MACRO> ...

2022-05-12 10:37:25    分类:技术分享    java   html   jstl   freemarker

What is the easiest way to render a freemarker object as JSON?

问题 回答1 您可以创建配置并设置 ObjectMapper 实例,如下所示: Configuration cfg = new Configuration(Configuration.VERSION_2_3_31); try { cfg.setSharedVariable("JSON", configuration.getObjectWrapper().wrap(new ObjectMapper())); } catch (TemplateModelException e) { throw new RuntimeException(e); } 使用此配置创建的模板可以按如下方式访问它以呈现您的对象: { "yourObjectPropertyName": ${JSON.writeValueAsString(yourObject)} } 回答2 我们为 FreeMarker 编写了一个简单的伪 DataLoader,它返回一个提供 stringify() 和 parse() 方法的“JSON”对象: package de.teambits.server.fmpp; import flexjson.JSONDeserializer; import flexjson.JSONSerializer; import fmpp.Engine; import fmpp.tdd

2022-05-12 09:45:09    分类:技术分享    json   freemarker

Freemarker: Dynamic interpolation of sub variables

问题 我正在尝试创建一个 FreeMarker 宏,它可以返回字符串连接和输入变量的插值: <#macro findValue var> <#if (.vars["foo." + var]) ??> .vars["foo." + var] <#else> ${.vars["bar." + var]} </#if> </#macro> 不幸的是,它不起作用。 首先, ${.vars["bar." + var]} ${.vars["bar." + var]}给出undefined的错误。 其次,即使我可以看到子变量确实存在, if条件也总是返回false 。 似乎.vars变量只能查找根变量,而不能查找像foo.test这样的子变量。 回答1 在 FreeMarker 中, foo.bar与foo["bar"]相同,但在[]中,您可以有一个计算为字符串的任意表达式。 所以你正在寻找的表达式只是foo[var] 。 顺便说一句,你的宏试图做的只是${foo[var]!bar[var]}

2022-05-04 03:31:50    分类:技术分享    freemarker

Content overlapping with header on second page of PDF

I am working on generating PDF using Freemarker which has dynamic contents. It can either be a single page PDF or multiple pages PDF depending upon the contents fetched from the external resource. The issue I am currently facing is with the multiple pages scenario. The content on second page is overlapped with the header. .ftl file <html> <head> <style> <#include "customStyles.css"/> @page { margin: 36px 36px 36px 36px; size: landscape; @top-center {content: element(header)} } #header {position: running(header);} </style> </head> <body> <div id="header"> <div class="headerText">Header Text<

2022-05-03 08:57:02    分类:问答    html   css   pdf   freemarker

java.lang.NoSuchFieldError: VERSION_2_3_0

I just upgraded my Struts2 version to 2.5.2 and started getting errors. My application doesn't even startup. I've made changes on the pom.xml and web.xml. I am not sure if I am missing any class but the log doesn't say that. pom.xml: <properties> <struts.version.no>2.5.2</struts.version.no> <tiles.version.no>3.0.5</tiles.version.no> </properties> <dependency> <groupId>ognl</groupId> <artifactId>ognl</artifactId> <version>3.1.8</version> </dependency> web.xml: <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter </filter

2022-05-03 03:09:51    分类:问答    java   maven   struts2   freemarker

What is the easiest way to render a freemarker object as JSON?

I have a data structure in freemarker which I would like to render as JSON notation in the output, similar to Javascript's JSON.stringify, is there something in freemarker such as object?json or any other simple way?

2022-05-02 13:22:26    分类:问答    json   freemarker

In Netsuite how can I include a list of tracking numbers in an email generated from an Item Fulfillment?

I need to send a custom "Order Shipped" email from an Item Fulfillment record in Netsuite. I am making the email template using freemarker. I would like to include the tracking numbers for packages associated with the Item Fulfillment in the email. I have tried using: <#list transaction.package as pkg>${pkg.packagetrackingnumber} </#list> However when I send the email template from the communication tab of an item fulfillment (that has multiple packages with tracking numbers) I see nothing in the email. I then tried: <#list transaction.package as pkg>TEST</#list> and still saw nothing (I would

2022-05-01 19:05:11    分类:问答    netsuite   freemarker

Freemarker: call a static util method from a template file (*.ftl)

In a Freemarker FTL file, I want to call StringUtils.capatilize(myString). For example: <p>You selected ${selectionString}.</p> <p>${StringUtils.capatilize(selectionString)} is great.</p> Can I somehow import org.apache.commons.lang3.StringUtils?

2022-04-30 13:21:27    分类:问答    freemarker