2016-03-18 129 views
0

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

「@」的解釋沒有任何變化,它總是像現在一樣使用。我懷疑添加JSP EL功能支持做出了某種改變。 TLD中的「財產」是什麼? – ddekany

+0

在問題 –

+0

中添加了tld您是否還有一個同名的'function'? – ddekany

回答

1

看來,當EL功能支持加入FreeMarker的2.3.22,它不認爲你可以有一個定製標記和EL函數同名。因此,該函數將覆蓋FreeMarker實現中的標記,因爲FreeMarker沒有用於指令和函數的單獨命名空間。不知怎的,這將在下一個版本(2.3.25)中得到解決。現在,如果自定義標籤和EL功能具有相同的名稱,則可以使用${tg.property("common.oldBrowserSection.title.firefox")}

+0

報告的bug:https://issues.apache.org/jira/browse/FREEMARKER-18 – ddekany

+0

現在已經修復Git。直到2.3.25出來(可能是幾個月),你可以使用這個補丁或者只是構建和使用開發版本:https://github.com/apache/incubator-freemarker/commit/c1d26de343756ca618b1fc4bc9e44d4611e141f6 – ddekany

相關問題