Gonçalo Cardoso
Gonçalo Cardoso

Reputation: 2262

Read jasper report programmatically

Some of my company consultants created multiple jasper reports (using iReports) which will be filled up programmatically using a Custom JRDataSource.

The problem is that I need to know which Elements are present in the report so that I can invoke the corresponding WebServices, so my question is: How can I programmatically, in Java, read the report so that I can identify every Element that needs to be filled up?

The reports can't be made all programmatically because there will be constant changes to their layout, and we can't be updating our software every time one of this changes occurs.

Upvotes: 0

Views: 1381

Answers (2)

Gonçalo Cardoso
Gonçalo Cardoso

Reputation: 2262

Managed to get all the Elements (fields) required by the report by using the following code:

JasperReport report = (JasperReport) JRLoader.loadObjectFromFile(path + "MyTestReport.jasper");
JRField[] gf = report.getFields();

Upvotes: 2

Joop Eggen
Joop Eggen

Reputation: 109557

As it is XML you can of course read all and parse your information.

As JasperReports works the other way round, pulling data via the JRDataSource, instead that structured data pushes, controls the output, it would be better if you could intercept the datasource. So if you can get the needed info from the data source, you can replace the data source (delegating to the original), or do AOP.

I am not sure to the exact requirements of your question. Maybe edit your answer to what exactly is the problem.

Upvotes: 2

Related Questions