我已使用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