基于Freemarker的组件

时间:2018-10-10 09:43:22

标签: freemarker opentext teamsite

我正在尝试在OpenText TeamSite / LiveSite 16上创建基于freemarker的组件。我创建了一个自定义freemarker皮肤:

enter image description here

在“外观”区域中,放置了以下代码:

<h1>${doc.book.title}</h1>

<h2>${doc.book.chapter[0].title}</h2>
<h2>${doc.book.chapter[1].title}</h2>

<#list doc.book.chapter as ch>
  <h2>${ch.title}</h2>
</#list>

<h1>${doc.book[0].title[0]}</h1>`

此模板来自Freemarker官方文档here

“上下文XML”区域:

<Data>
  <External>
    <Object Scope="local">com.sayHello.Books</Object>
    <Method>books</Method>
  </External>
</Data>

这将调用“ books”方法,该方法将返回XML文档:

public Document books(RequestContext context) {
    Document doc = Dom4jUtils.newDocument();

    Element docElement = DocumentHelper.createElement("book");

    docElement.addElement("title").addText("Test Book");

    Element chapterElement = DocumentHelper.createElement("chapter");

    chapterElement.addElement("title").addText("Chapter 1");

    Element anotherChapterElement = DocumentHelper.createElement("chapter");

    anotherChapterElement.addElement("title").addText("Chapter 2");

    docElement.add(chapterElement);

    docElement.add(anotherChapterElement);

    doc.add(docElement);

    return doc;
}

每当预览组件时,都会出现以下错误:

2018-10-10 10:26:32,528 ERROR [freemarker.runtime] Error executing FreeMarker template
FreeMarker template error:
For "${...}" content: Expected a string or something automatically convertible to string (number, date or boolean), or "template output" , but this has evaluated to a sequence+hash (wrapper
==> doc.book.title  [in template "template" at line 2, column 7]


Tip: This XML query result can't be used as string because for that it had to contain exactly 1 XML node, but it contains 0 nodes. That is, the constructing XML query has found no matches.

FTL stack trace ("~" means nesting-related):
    - Failed at: ${doc.book.title}  [in template "template" at line 2, column 5]

我想我没有正确访问TeamSite内的模板元素,Freemarker模板在TeamSite之外可以正常工作。

感谢您的帮助。

0 个答案:

没有答案