2016-03-18 131 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

相关问题