Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
548 views
in Technique[技术] by (71.8m points)

java - Jasper Report Print Custom Objects in Arraylist

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...