同事在调试Freemark遇到如下错误:
Error executing macro: freeBackTable required parameter: itemList is not specified.……
由于此前我没有了解过Freemark。因此,google中检索了一下,很多帖子说是空值问题。同事认为不是。但是,随后我在阅读Freemark官方的FAQ中发现有如下说明。因此,我认为这是null值引起的。
17. What about null and the FreeMarker template language?
The FreeMarker template language doesn't know the Java language null at all. It doesn't have null keyword, and it can't test if something is null or not. When it technically faces with a null, it treats it exactly as a missing variable.
也就是说当FreeMarker程序中遇到null引用,会认为这个值没有声明。于是运行项目发现模板的908行报同样错误。其中有形如如下语句<@itemList=freeBackTable.itemList/>。因此我怀疑Struts2的对象为null,从而导致宏语句
“<#macro freeBackTable project reformingFeedBack itemList checkNotifyingFM index>”中声明的itemList引用了一个空值,按照官方的说明,相当于“a missing variable”也就是说“not specified”。
因此,加上Freemark的判断,在对“itemList”赋值语句前增加如下判断:“<#if freeBackTable.itemList?exists && freeBackTable.itemList?has_content>”,结果如下所示
<#if freeBackTable.itemList?exists && freeBackTable.itemList?has_content>
<@itemList=freeBackTable.itemList />
</#if>
再次运行程序,问题解决。在使用Freemark自定义的变量前,如果变量引用了一个第三方传递过来的对象,应该先判断该对像是否为null,在赋值给这个自定义变量。
分享到:
相关推荐
一些很不错的freemark资料及eclipse的freemark插件
freemark开发指南详解freemark开发指南详解freemark开发指南详解freemark开发指南详解freemark开发指南详解
主要介绍了freemark标签的相关基础知识,基本上了解Freemark标签的应用
freemark中文资料 freemark教程 freemark基础和高级教程
freemark ,
Freemark指南:全面介绍Freemark的使用方法,让你的页面已程序完美的结合!
FREEMARK资料,开发入门指南 是开发人员了解FREEMARK的一本入门资料
freemark模板&模版技术&freemark模板&模版技术
freemark 2.3.19 中文教程
freemark生成静态页面,直接导入该项目 使用JDK1.6。直接运行代码中的CreateHtmlWebSite.java, 即可在webroot下面生成MyWebSite.html静态页面。
freemark比较实用的手册,中文版 适合快速学习
FreeMark jar包,中文官方文档。FreeMark jar包,中文官方文档。
freemark资料
SpringMVC+Freemark简单整合 不含lib下的jar。
freemark标签使用的一些说明.希望对大家有点用。
freemark 模板引擎 概述 教程 5分钟入门 pdf
freemark从入门到精通,freemark讲解,从小白到大明白。
springmvc+mybats+freemark(mvn)
本人觉得比较好的freemark学习文档