FreeMarker テンプレート エンジンで XDocReports を使用して、テンプレートに基づいてドキュメントを生成しています。Java リストからテーブルを生成したいと考えています。私のコードは次のようになります。
try {
// 1) Load Docx file by filling Freemarker template engine and cache
// it to the registry
InputStream in = ReportWriter.class.getResourceAsStream("/template/teszt_jegyzokonyv_template.docx");
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, TemplateEngineKind.Freemarker);
FieldsMetadata metadata = report.createFieldsMetadata();
metadata.load( "testCaseGroups", TestCaseGroup.class, true );
metadata.load( "testCases", TestCase.class, true );
// 2) Create context Java model
IContext context = report.createContext();
TestCaseGroup testCaseGroup1 = new TestCaseGroup("TestCaseGroup1", Lists.newArrayList(new TestCase("description1"), new TestCase("description3")));
TestCaseGroup testCaseGroup2 = new TestCaseGroup("TestCaseGroup2", Lists.newArrayList(new TestCase("description1"), new TestCase("description3")));
context.put("testCaseGroups", Lists.newArrayList(testCaseGroup1, testCaseGroup2));
// 3) Generate report by merging Java model with the Docx
OutputStream out = new FileOutputStream(new File("DocxProjectWithFreemarker_Out2.docx"));
report.process(context, out);
} catch (IOException e) {
e.printStackTrace();
} catch (XDocReportException e) {
e.printStackTrace();
}
エンティティは次のようになります。
public class TestCaseGroup {
public String name;
public List<TestCase> testCases;
public TestCaseGroup(String name, List<TestCase> testCases) {
this.name = name;
this.testCases = testCases;
}
public String getName() {
return name;
}
public List<TestCase> getTestCases() {
return testCases;
}
}
テストケース
public class TestCase {
public String description;
public TestCase(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
}
テンプレート:
しかし、次の例外があります。
原因: freemarker.core.InvalidReferenceException: 以下が null または不足していると評価されました: ==> testCases
私は何を間違っていますか?