xdocreport - How can I generate table in docx with freemarker? -
i'm using xdocreports freemarker template engine generate documents based on template. want generate table java list. code looks this:
try { // 1) load docx file filling freemarker template engine , cache // 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 merging java model docx outputstream out = new fileoutputstream(new file("docxprojectwithfreemarker_out2.docx")); report.process(context, out); } catch (ioexception e) { e.printstacktrace(); } catch (xdocreportexception e) { e.printstacktrace(); }
the entities looks this:
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; } }
testcase
public class testcase { public string description; public testcase(string description) { this.description = description; } public string getdescription() { return description; } }
the template:
but i've got following exception:
caused by: freemarker.core.invalidreferenceexception: following has evaluated null or missing: ==> testcases
what doing wrong?
Comments
Post a Comment