Jasper报告在Arraylist中打印自定义对象 [英] Jasper Report Print Custom Objects in Arraylist

查看:375
本文介绍了Jasper报告在Arraylist中打印自定义对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一个List作为参数传递给Jasper如下。

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());

现在我能够在jasper中检索issuesList但我无法在CustomObject中检索值。

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>

当我想访问Custom Object中的字段值时抛出异常,例如

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 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$

在Mike答案的帮助下用JasperReports打印一个arraylist内容
我已经在jasper中迭代了我的Arraylist。任何帮助高度赞赏。

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

推荐答案

当我从对象 CustomObject
跟随

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>

这篇关于Jasper报告在Arraylist中打印自定义对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆