Holder null value generate UnexpectedTypeException

49 views
Skip to first unread message

Олег Наумов

unread,
Jan 13, 2017, 6:08:19 AM1/13/17
to xdocreport
Lets look my problem on structure from your example:

List<Map<String,String>> developers = new ArrayList<Map<String,String>>();
Map<String,String> developer1 = new HashMap<String, String>();
developer1.put("Name", "ZERR");
developer1.put("LastName", "Angelo");
developer1.put("Mail", "angel...@gmail.com");
developers.add(developer1);
Map<String,String> developer2 = new HashMap<String, String>();
developer2.put("Name", "Leclercq");
developer2.put("LastName", "Pascal");
// developer2.put("Mail", "pascal....@gmail.com"); // one without field Email !!!!
developers.add(developer2);
context.put("developers", developers);

It's emulation of collection of developers (without real developer model).

In my situation we can have developer without field "mail" (for example). And I want handle this situation, if property is null when not display it.

«${developers.name

${developers.email?if_exists}


This stucture throw next exeption:

freemarker.core.UnexpectedTypeException: For "." left-hand operand: Expected a hash, but this evaluated to a sequence (wrapper: f.t.SimpleSequence): ==> developers[in template "fr.opensagres.xdocreport.document.docx.DocxReport@6105ac32!word/document.xml" at line 4, column 2707] The failing instruction: ==> #if developers.email?? [in template "fr.opensagres.xdocreport.document.docx.DocxReport@6105ac32!word/document.xml" at line 4, column 2702]


But if I use default FreeMarker sintax:

«@row[#list developers as d]»«${(d.name)!}»«@/row[/#list]»

 

«${d.email?if_exists}»



Is it possible handle null field if I want use: FieldsMetadata (addFieldAsList)?


Reply all
Reply to author
Forward
0 new messages