Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...