我已使用freemarker版本2.3.20。将其更新到2.3.22后,ftl模板中的自定义标记不再起作用。我使用的下一个自定义标签更新至版本2.3.22后,自定义标签无法在freemarker中工作
<#assign tg=JspTaglibs["/WEB-INF/tld/tg.tld"]/>
<@tg.property key="common.oldBrowserSection.title.firefox"/>
FreeMarker的更新版本2.3.23后我收到
Caused by: freemarker.core.NonUserDefinedDirectiveLikeException: For "@" callee:
Expected a(n) user-defined directive, transform or macro, but this has evaluated to
a method+sequence (wrapper: f.e.b.SimpleMethodModel):
tg.property [in template "WEB INF/freemarker/common/warning/oldBrowserWarning.ftl"
at line 6, column 11]
Tip: Maybe using obj.something(params) instead of obj.something will yield the
desired value
FTL stack trace ("~" means nesting-related):
- Failed at:
@tg.property key="common.oldBrowserS... [in template "WEB-INF/freemarker/common/warning/oldBrowserWarning.ftl"
at line 6, column 9]
看起来像“@”符号的问题。 Freemarker将它识别为宏。所以我的问题是新的Freemaker版本中这个问题的原因是什么,以及如何解决这个问题,而不需要修改所有的ftl模板(也许改变一些配置)。
<?xml version="1.0" encoding="UTF-8"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>
tag library
</description>
<tlib-version>1.0</tlib-version>
<short-name>tg</short-name>
....
<tag>
<description>propertyT</description>
<name>property</name>
<tag-class>tg.pack.custom.PropertyTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>key</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>canUseHtml</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>urlEncode</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>doProcessAttributes</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>escapeQuotes</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>escapeHtml</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>useUserEncode</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>js</name>
<description>pass property to Javascript</description>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
....
</taglib>
功能TLD:
<function>
<description>
return localization value
</description>
<name>property</name>
<function-class>td.app.customtag.Function</function-class>
<function-signature>
java.lang.String property(java.lang.Integer, java.lang.Integer, java.lang.String)
</function-signature>
</function>
“@”的解释没有任何变化,它总是像现在一样使用。我怀疑添加JSP EL功能支持做出了某种改变。 TLD中的“财产”是什么? – ddekany
在问题 –
中添加了tld您是否还有一个同名的'function'? – ddekany