【发布时间】:2017-02-03 20:19:36
【问题描述】:
我将 List 作为参数传递给 Jasper,如下所示。
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 中检索问题列表,但无法在 CustomObject 中检索值。
使用以下方法迭代的 CustomObject 的以下作品和打印参考
<textFieldExpression><![CDATA[$P{list}.get($V{ROW_INDEX})]]></textFieldExpression>
当我想访问自定义对象中的字段值时,这会引发异常,例如
<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 Answer 的帮助下Print an arraylist content with JasperReports 我已经在 jasper 中迭代了我的 Arraylist。任何帮助都非常感谢。
【问题讨论】:
-
我不认识 jasper,但这个错误
Exception obtained is: The method getCustomMethod() is undefined for the type Object value给我的印象是,从列表中获得的实例的声明类型不是CustomObject,而只是Object。尝试找到一种方法将它们投射到CustomObject。 -
你是对的,当我在 JRXML 中键入 cast as 时,这对我有用
-
太棒了 :) 不要犹豫,写一个答案并接受它。它可以帮助其他人。
-
感谢大卫 刚刚完成。请您为此投票。
-
不客气。你应该写一个答案而不是编辑问题:) 只需发布一个答案并将解决方案移到其中。
标签: java jasper-reports