I am new to JSF, I want to integrate JSF with Jasper report. I am generating custom report from server side, that report should display into the UI using JSF components. How to do that? Could you please provide the JSF and Jasper Report Simple Program and required libraries.
Assuming that you're talking about HTML reports of JasperReports, your best bet is to forget about the JSF bit at this stage, since this is irrelevant for JasperReports. In turn, JSF also can't do anything sensible with "3rd party" HTML. Just add a HTML <iframe>
element to the JSF page whose src
points to the URL of a HttpServlet
instance which returns the desired HTML report of JasperReports based on request parameters or pathinfo, which you in turn can pass dynamically using EL. E.g.:
<iframe width="600" height="400" src="reportservlet?id=${bean.someid}"></iframe>
The HttpServlet
behind the url-pattern
of /reportservlet
has just to invoke JasperReports as per its documentation/tutorials, obtain an InputStream
of it and write it to the OutputStream
of the HttpServletResponse
along with a correct set of response headers, at least the Content-Type
is important.
BalusC suggestion seems good in case you want HTML reports. Here is my answer in case you wanted any other format (say PDF)
Make an Ajax request on the servlet to "prepare" the report and store it somewhere then return you the ID of the newly created report.
The response comes back with either success or fail. In case of success you popup a new window with a hypothetical URL and stream the PDF file to it (using the ID you have)