Jasper Report Print Custom Objects in Arraylist

半腔热情 提交于 2019-12-25 18:51:57

问题


I am passing a List as paramter to Jasper as following.

Map<String, Object> model=new HashMap<>();
  List<CustomObject> issues=new ArrayList<>();
            issues.add(new CustomObject(1,"AIRPORT Services","XYZ","asdfa","asdf","asddf"));
            issues.add(new CustomObject(1,"AIRPORT Services","XYZ","asdfa","asdf","asddf"));
            model.put("issues",issues);
            JasperPrint jasperPrint1 = JasperFillManager.fillReport(report, model, new JREmptyDataSource());

Now I am able to retrieve issuesList in jasper but I can't retrieve value inside CustomObject.

Following works and prints reference of CustomObject iterated using following

<textFieldExpression><![CDATA[$P{list}.get($V{ROW_INDEX})]]></textFieldExpression>

This throws exception when I want to access value of field inside Custom Object such as

<textFieldExpression><![CDATA[$P{list}.get($V{ROW_INDEX}).getCustomMethod()]]>

Exception:

Exception obtained is: The method getCustomMethod() is undefined for the type Object value = ((java.util.List)parameter_list.getValue()).get(((java.lang.Integer)variable_ROW_INDEX.getValue())).getCustomMethod(); //$JR_EXPR_ID=0$

With Help of Mike Answer at Print an arraylist content with JasperReports I have iterated my Arraylist in jasper. Any help highly appreciated.


回答1:


This worked for me when I just cast from Object to CustomObject like as follow

<textFieldExpression><![CDATA[((com.custom.CustomObject)$P{flightIssues}.get($V{ROW_INDEX})).getCustomeMethod()]]></textFieldExpression>


来源:https://stackoverflow.com/questions/42032400/jasper-report-print-custom-objects-in-arraylist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!