2

This question is about Jasper Reports.

Suppose I want to create a Jasper Report using JRBeanCollectionDataSource like this ...

jasperPrint = JasperFillManager.fillReport(JRLoader.getInputStream(fileName), parameters, new JRBeanCollectionDataSource(aList));

And suppose that the PoJo I am using has a Property of type List.

How can I access

  1. The individual items in this List,
  2. and if this item is itself a Pojo access it's properties in Jasper Report XML file.

For example in the Jasper XML file:

...field name="?????" class="java.lang.String" ...

Thanks for your help ...

1 Answer 1

6

If your data source has fields of type List (more generally, of type java.util.Collection), then you can use a Table or List or Subreport component to iterate through them. Use one of those elements and set its data source like this:

new net.sf.jasperreports.engine.data.JRMapCollectionDataSource($F{myListField})

You could also add your own helper class with a static method to deal with these fields appropriately.

This comes up a lot with MongoDB. I wrote an article on Collections in JasperReports. It uses MongoDB as the data source... but it would apply equally well to your POJO data source.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much for your help. I also found this page about this issue: brucephillips.name/blog/index.cfm/2008/7/12/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.