Jump to content
Changes to the Jaspersoft community edition download ×

JasperReports used in a J2EE application

Recommended Posts

By: ziggy - zarthstar

JasperReports used in a J2EE application

2004-11-08 20:53

Hi all,


I'm fairly new to JasperReports and I'm looking for an example or use case where JasperReports is used in a J2EE web application to create a generic reporting engine.


The high-level requirements looks something like this:


1. Extensibility. The ability to add new reports with data coming from an RDBMS.


2. Create dynamic, ad hoc reports that are filterable by data valid to the report and entered by the report user


3. Integrate into an existing home-grown, struts-like (MVC) architecture using JSPs, Servlets and Plain old JavaBeans


4. Displayed using JSP/HTML


5. Exportable to XLS and PDF


Any info is greatly appreciated. If you know of any good books or articles that would be great.







By: Darren Hartford - binarymonk

RE: JasperReports used in a J2EE application

2004-11-16 05:44

Hi Ziggy,

I have a working JasperReport system running in J2EE/Jboss space, but it presently is app-specific.


I'm currently working on a generic JasperReport server (just started, short timeline) that the first iteration will be Tomcat only, and then eventually may extend to be a 'J2EE' compliant applicaiton and add in JMS support and some other items as-needed. Checking with 'da boss' if can open source.


If you need something right away, you can look at OpenReports at http://oreports.sf.net . It's GPL'd and I really didn't have luck accessing it from outside it's GUI (i.e. API/calling from another application).





By: Edgar Dollin - edollin

RE: JasperReports used in a J2EE application

2004-11-16 08:37

I have one also njmvcopensource on sourceforge.


The report parameters are xml files. The user can save or delete these to create 'customized' reports. There is a set of generic front end report screens where you can select a report, the parameters are displayed and then you can run the report. Of course you can write your own data entry screen for the report and the reports can be embedded via links from elsewhere. The reporting system is designed to be embedded in any arbitrary system with configuration options and interfaces to allow the system to be controlled within another system.


It is currently running under tomcat but there is no tomcat specific code.






By: ziggy - zarthstar

RE: JasperReports used in a J2EE application

2004-11-16 10:09

Hi Darren and Edgar,


Thank you for your responses. They have been very helpful.


Would either of you be willing to send me the source code for the projects you are working on? I will use it strictly for reference.







By: Darren Hartford - binarymonk

RE: JasperReports used in a J2EE application

2004-11-17 06:42

Ran into a pretty big problem with the Tomcat-based server (and will also be a problem with J2EE/Jboss) -




I have no idea how to handle subreports in a web-based server environment where the JRDataSources and the Parameters are de-coupled from the Report. The Reports are also stored in arbitrary locations (i.e. the existing prototype code is storing the pre-compiled JASPER file as a BLOB in a database). I admit some ignorance into the specific of JasperReports itself, as I use the iReport design tool for report creation.


I don't suppose anyone would have some insight into handling Subreports for Tomcat or J2EE JasperReport servers do they?





By: Craig O'Shannessy - shanness

RE: JasperReports used in a J2EE application

2004-11-17 16:04

Basically the problem with Subreports is threading.


The EJB spec states that it's illegal to start new threads within an EJB context (this is because JBoss, like other EJB containers uses threads to store the transactional etc information). So when a Jasper subreport spawns a new thread, that new thread has NO transactional context!


The easiest way around this, at least for me is to convert all the entitiy beans that are going to be used in the subreport into value objects (aka DTO's). This is easy if you are using something like XDoclet, which will generate your value objects on each compile cycle.


See this thread.







By: Darren Hartford - binarymonk

RE: JasperReports used in a J2EE application

2004-11-18 07:05

Hi Craig,

Yes, I have read that article and have the threading problem noted, but does that isn't exactly the problem I have.


The problem is higher-level, as in the abstractness/design of HOW to handle subreports. Normally, you would have a master report that has a pointer to subreports and pass parameters from the master report to the subreport.


Problem 1: The location to point to the subreport. The jasperreport samples do give an example, and I have a work-around where there is a location to get the binary/byte[] version of the JasperFile.


Problem 2: Actually doing the passing of parameters when everything is decoupled! Maybe this is already built-in to JasperReports, regardless of the environment?


Once past those two problems, the third one is the real trick - subreports usually have their own JRDataSource/Query. If the JRDataSource is decoupled, how will JasperReports know which one to use (i.e. the JDBC connection and the Query for the report are stored in a database)?


Problem 3: passing de-coupled Connection and Query information to the subreport in such an environment.


I think that's it actually (other than threading, but that's only a problem in J2EE world).






By: Craig O'Shannessy - shanness

RE: JasperReports used in a J2EE application

2004-11-18 17:12

Hi Darren,


I assume you mean you want to keep the coupling out of the XML? E.g. at master report design time, you don't know the subreport and/or it's parameters?


It seems to me that you need a controller that can do runtime coupling for you.


Assuming this is the case, you can programmatically alter reports at runtime. I haven't played with this part of the API, and unfortunately there is no JavaDoc, which makes it difficult, but I believe it is possible to alter all parts of a compiled report.


Check out the alterdesign sample report.


Hope this helps, and that I have understood your problem domain.



By: Noel Kee - noelkee

RE: JasperReports used in a J2EE application

2004-11-22 23:30

The subreports can be handled as URL or InputStream. What I tried last time with JasperReports 0.5.0 was to use


this.getClass().getResource({relative path to subreport})




this.getClass().getResourceAsStream({relative path to subreport})


for this purpose. Not too sure if it worked the last time, but you can try it out. Let me know if it works.



By: Joshua Toepfer - o_doil_rules

RE: JasperReports used in a J2EE application

2005-04-21 06:59



I to am fairly new to jasper reports, however, I broke down my reporting system into steps.


Step 1: Choosing a Report


Step 2: Obtain Selection Criteria from User (which may include limiting the number of fields on the report - or filtered data based on security --- tiles works wonderful).


Step 3: Fetch/Compile Report (I also build a filtering mechanism to filter items on the report per another XML doc, this allows for extensibility.)


Step 4: Fill/Print/Export Report.


So far I've integrated Struts, Tiles, and JasperReports into the system. My problem it's too fast. JasperReports threads when compiling reports and sometimes I get empty reports with no data because the reports are not completely compiled.

I've resorted to putting timing loops for delays in my app, to account for the time. However, it doesn't always work with the large reports. It's been kind of hit and miss.






By: Srinivas Nelakuditi - vasutech

RE: JasperReports used in a J2EE application

2005-04-21 09:57

Take a look at generic jasper framework for web in this forum. It has all the features that you are trying to do. May be it will be a good start for you.

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...