我的模板中有这个函数来显示一棵树并使用 freemarker 2.0 :
function doBeforeToggle() {}
var ar1=new Array();
var CurrentTree = null;
var label = null;
<assign First = "true">
<foreach Node in PUBLISH._children._descendantOrSelf>
<if First = "true" >
var tree=new WebFXTree("${Node.@Label._text}");
ar1["${Node.@NodeID._text}"] = tree;
<assign First = "false">
<else>
var NewTree = new WebFXTreeItem("${Node.@Label._text}");
<if Node.@File>
NewTree.action = "${Node.@File._text}"
<else>
NewTree.icon = webFXTreeConfig.folderIcon;
</if>
ar1["${Node.@NodeID._text}"] = NewTree;
CurrentTree=ar1["${Node._parent.@NodeID._text}"];
CurrentTree.add(NewTree);
</if>
</foreach>
document.write(tree);
在我升级到 freemarker 2.3.19 之前它工作正常。现在它抛出这个错误:
java.lang.NoSuchMethodError: org.jdom.Element.getParent()Lorg/jdom/Element;
at freemarker.ext.jdom.NodeListModel.getParent(NodeListModel.java:847)
at freemarker.ext.jdom.NodeListModel.access$1100(NodeListModel.java:122)
at freemarker.ext.jdom.NodeListModel$ParentOp.operate(NodeListModel.java:868)
at freemarker.ext.jdom.NodeListModel.evaluateElementOperation(NodeListModel.java:1035)
at freemarker.ext.jdom.NodeListModel.get(NodeListModel.java:473)
at freemarker.core.Dot._getAsTemplateModel(Dot.java:76)
at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at freemarker.core.Dot._getAsTemplateModel(Dot.java:74)
at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at freemarker.core.Dot._getAsTemplateModel(Dot.java:74)
at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at freemarker.core.Expression.getStringValue(Expression.java:93)
at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
at freemarker.core.Environment.visit(Environment.java:221)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:221)
at freemarker.core.IfBlock.accept(IfBlock.java:82)
at freemarker.core.Environment.visit(Environment.java:221)
at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:167)
at freemarker.core.Environment.visit(Environment.java:428)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
at freemarker.core.Environment.visit(Environment.java:221)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:221)
at freemarker.core.Environment.process(Environment.java:199)
at freemarker.template.Template.process(Template.java:259)
如果我删除以下代码行:
CurrentTree=ar1["${Node._parent.@NodeID._text}"];
我不再有这个错误,但树没有很好地显示。
经过一番研究,我发现他们是一个补丁,通过将 getParent 替换为 getParentElement 来修复 NodeListModel.java。当我通过添加固定的 NodeListModel.java 覆盖这个类时,一切正常。
但我想知道他们是否是不添加此补丁的另一种解决方案,也许我需要更改 xml 格式或用其他东西替换 Node._parent。
预先感谢您的任何帮助。
卡琳娜