JasperReport - JavaBean Data Sources from official documentation

Tag: jasper-reports Author: A190742292 Date: 2011-09-14

JavaBean from official documentation:


"For instance, to retrieve the value of a report field named address, the program will try to call through reflection a method called getAddress() on the current JavaBean object. "

From my experience, I'm almost certain that it is not on the current object, but on all JavaBean objects (of a given type) that are passed as a collection or a list.

When I try to print an atribute of a specific instance of a bean, it prints all the values of all instances of that bean. Anyone knows how to pass this?

Other Answer1

How are you printing your attribute? If it is by putting a textField into a detail band, then that behaviour is correct. This is because the detail band is repeated once for every record in the dataset. If you are using a bean datasource this means that accessing the field address from the detail band will call getAddress() for every bean in the collection.

If you don't want an element to be repeated, move it to a different band. Or if you want to print the value only for a specific bean, add a printWhenExpression to your element.


First of all, thank you for your reply. I actually want to pass the values for a specific bean and curiously I was thinking about printWhenExpression but it didn't sound me as a "clear" solution. Do I have to consider another bean attribute that relates a child bean with is parent bean? or there is a cleaner way to use printWhenExpression? A more complete explanation of my problem goes here: jasperforge.org/plugins/espforum/…. Thanks again.