views:

487

answers:

3

Hi there,

I am trying to use Jasper Reports (v3.5.2) to generate and print reports in PDF/HTML to the browser for a webapp. This webapp already uses JSF(Woodstock) for the front end and EJB 3 (with JPA and Hibernate as persistence provider to a MySQL db).

My question is - where should the code for generating the Jasper based reports be at? I am totally confused about this. Should I put it in the JSF front end? Or should it be a "report" module in the business logic as session beans?

I would think that the right place for this is the business tier as a separate module. I would call a business method with the name of the report, input parameter map and report format as parameters to the business method and would get the generated pdf/html in return which I could then send to the browser. Am I on the right track with this?

Can you suggest a pattern for how to go about doing this?

Also, I would like to use EJBQL since I am already using JPA.

Thanks.

+3  A: 

If you are going to embed the jasper generating as part of your ear, then I would say it should be abstracted in a class as you suggest. I'm not sure I would make a separate EJB for it, unless you are doing clustering or otherwise going to offload the report generation on to another JVM, or you have some special transactional needs.

Another common option is to have a completely separate report server which you would call remotely, and it would take over interaction with the user.

Yishai
+1  A: 

I'm assuming here that 'code for generating' = 'api to invoke the report'.

You'll mostly want to do this via the presentation tier - where libraries in the presentation tier contact the resources in the reporting tier only to stream the report down to the user.

This way, you'll avoid having to hold the data and keep passing it across tiers before you actually send it to the requestor (client)

Ryan Fernandes
A: 

There's a few ways to go about this. You could generate the report from a managed bean, be aware that you may have to break the JSF lifecycle for this by invoking facesContext.responseComplete() just before rendering your report in your browser.

Another solution could be to have a report servlet that you can invoke from a JSF output link whenever you need to generate a report.

Ensode