0

I have this function in my template to show a tree and using 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);

It was working fine until i upgrade to freemarker 2.3.19. Now it is throwing this error :

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)

If i remove the following line of code:

CurrentTree=ar1["${Node._parent.@NodeID._text}"];

I dont have this error anymore but the tree is not well displayed.

After some research, i found their is a patch which fix NodeListModel.java by replacing getParent by getParentElement. When i override this class by adding the fixed NodeListModel.java, everything works fine.

But i was wondering if their is another solution without adding this patch, maybe i need to change the xml format or replace Node._parent by something else.

Thank you in advance for any help.

Carine

2 Answers 2

1

Back in 2004, when JDOM was in 'beta', the getParent() signature was changed and the getParentElement() was added. Freemarker is compiled with JDOM beta 0.8 (from 2002 - 11 years ago).

I would recommend that you contact the Freemarker tean and suggest an update to support both JDOM 1.1.3 as well as 2.0.5

4
  • FreeMarker does that with some other optional dependencies too, like it supports multiple Python versions. OTOH I wonder how many out there are still using the JDOM support anyway. It was meant to be removed for a long time, but it can't be per version policy pror FM 2.4.0. Also, the OP upgraded from FreeMarker 2.0 from 2002... that's no joke, as prior mid-2004 FreeMarker wasn't exactly famous from being disciplined regarding backward compatibility...
    – ddekany
    Oct 14, 2013 at 15:39
  • Take my answer from the perspective that I am the JDOM Maintainer. it worries me that there are actively maintained projects like FreeMaker that use beta-version API's. The JDOM API was stabilized in the 1.0 release many years ago, and maintains full backward compatibility for all versions until 2.0, which introduces generics. I can help the FreeMaker folk take full advantage of both JDOM 1.x and 2.x if they want.
    – rolfl
    Oct 14, 2013 at 16:00
  • While FreeMarker is actively developed, the case of freemarker.ext packages is a bit more complicated... They are extensions (like, add-ons), most of them should have been in a separate optional jar. And not all of them are actively maintained... like the JDOM or Rhino package is pretty much abandoned.
    – ddekany
    Oct 14, 2013 at 16:44
  • @ddekany - I see you maintain the FreeMarker suite. I have not used it (and picked up on this SO Question because of the JDOM tag). It is apparent to me that the 'correct' solution for the OP is to use an updated NodeListModel. It would be relatively trivial to update the existing JDOM 0.8 model to JDOM 1.x, and to add another JDOM2 model using the (mostly similar) JDOM 2.0.x API (but with packages in the org.jdom2.* namespace). If you are interested in a submission I can push through the work....
    – rolfl
    Oct 14, 2013 at 17:14
0

Try using JDOM 0.8 beta... or, you can copy freemareker.ext.jdom into another package, patch it there, and then use that for wrapping the JDOM object. (Or, if there's enough demand for it, it could be improved in FreeMarker, so that it supports multiple JDOM versions.)

BTW, ar1["${Node._parent.@NodeID._text}"] can just be written as ar1[Node._parent.@NodeID._text], although the error will not go away because of that.

2
  • I would recommend against using JDOM 0.8 (it has a number of problems that are resolved in the multiple JDOM versions released since 2002....). FreeMarker is currently being actively developed. If the Freemarker maintainers are intersted I can help migrate their systems to support both JDOM 1.x and 2.x ... it's reltively trivial.
    – rolfl
    Oct 14, 2013 at 16:02
  • Well, I guess it's not that hard to do... It's just that freemarker.ext.jdom itself is deprecated. That's why I'm saying it would be good to know how many are still using it.
    – ddekany
    Oct 14, 2013 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.