0

Open JasperReport File in new Window of webBrowser

asked 2008-11-05 22:21:30 +0800

intoxicadocoder gravatar image intoxicadocoder
57 1 1 4

updated 2008-11-06 14:24:04 +0800

Hi I want open a jasperreport output file generated in new Window of browser
Im trying:
Executions.getCurrent().sendRedirect("the_url_generated_of_report","_blank");

but I can not found a method that returns me the url of output file generated by Jasper
Exists anyone way to solve this problem?
thanks so much!!!

delete flag offensive retag edit

13 Replies

Sort by » oldest newest

answered 2008-11-06 02:57:17 +0800

robertlee gravatar image robertlee
561

If you know your output URL then you should try to pass the value by using setAttribute method or the custom-attribute component. See:

http://www.zkoss.org/doc/devguide-single/index.html#id459905

Hope this helps.

link publish delete flag offensive edit

answered 2008-11-06 12:17:12 +0800

intoxicadocoder gravatar image intoxicadocoder
57 1 1 4

updated 2008-11-06 14:23:32 +0800

thanks
but my question is how I can obtain the_url_generated_of_report? y was research in source code of jasperreport component and am not found anyone method that returns me it

link publish delete flag offensive edit

answered 2008-11-07 04:23:02 +0800

robertlee gravatar image robertlee
561

How do you set your output directory?

link publish delete flag offensive edit

answered 2008-11-07 06:09:33 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

I think ZK jasperreport component doesn't provide an url for downloading or external usage.
please post it to feature request .

link publish delete flag offensive edit

answered 2010-02-03 10:21:38 +0800

xmedeko gravatar image xmedeko
1031 1 16
http://xmedeko.blogspot.c...

Hi,

this is a little bit old thread, but I have seen more people asking this, so one solution is here: http://zh.zkoss.org/forum/listComment/2677

But I think this solution is too much memory consuming - the whole PDF stored in session. Also, the user cannot "reload" the report. And the PDF will stay in the session, if something wrong happens and the client browser would not trigger the jasperreport servlet. At least the soft references should be used, to avoid out of memory error.

Other solution it to pass into the session just the Jasper Report, like # net.sf.jasperreports.j2ee.servlets.PdfServlet. But again, soft references should be used.

IMHO the best solution is the old good way of passing to the "jasperreport servlet" just a few parameters in URL query string, e.g. ?id1=XXX&id2=YYYY and then the servlet should create the report.

If you cannot pass parameters in URL, then put them into the session, usually they will take much less memory then the PDF. In this situation you can use soft/weak references in this way. Usage of weak references:
- store the parameters in the original desktop/page
- make a weak references and store them into the session, or use weak hash map
- open "jasperreport servlet" in a new window. the user can now reload "reload" the report as long as the weak references exists, that is as long as the original desktop/page exists

link publish delete flag offensive edit

answered 2010-02-03 13:23:25 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

xmedeko@ not interessted?

link publish delete flag offensive edit

answered 2010-02-03 18:06:11 +0800

smigol gravatar image smigol flag of Italy
316 2

updated 2010-02-03 18:55:50 +0800

I agree with @xmedeko
@intoxicadocoder, however I use JasperReport since 4 years to produce real-time reports ... I never stored report in session or file-system server ...
In my application, I open a new window and call a Custom JasperReport Servlet passing parameters (POST method ... but you can also pass in GET) ...
below, that's all step to create one servlet Custom JasperReport Servlet:
1) Compile. Jrxml to. Jasper if it has been updated externally (it's optional, you can use directly. Jasper compiled file):
use
JasperReport jasperReport = JasperCompileManager.compileReportToFile (java.lang.String sourceFileName,
                                       java.lang.String destFileName)

2) Fill. Jasper with the data (ex. your params can be used to retrieve data from a database with a custom query)
use
JasperPrint jasperPrint = JasperFillManager.fillReport (JasperReport jasperReport,
                                     java.util.Map parameters,
                                     JRDataSource dataSource)

where
JasperReport jasperReport = (JasperReport) JRLoader.loadObject (jasperFilePath)
JRDataSource dataSource = new JRResultSetDataSource(<b >Resultset</b>);

3) Export the report in your preferred format using an extension of :
JRAbstractExporter

- PDF: JRPdfExporter
- XML: JRXmlExporter
- XLS: JRXlsExporter
- CSV: JRCsvExporter
- TXT: JRTextExporter

... and passing in JRAbstractExporter.setParameters, the param of output type:
- TO FILE: JRAbstractExporter.OUTPUT_FILE_NAME filePathDestinationStr
- TO STREAM: JRAbstractExporter.OUTPUT_STREAM outputStreamObject

example:
httpResponse.setContentType("application/pdf");
httpResponse.setHeader("Content-disposition", "attachment; filename=MyFile.pdf");
ServletOutputStream out = httpResponse.getOutputStream();

//STEP 1: COMPILE REPORT (OPTIONAL ... U CAN USE DIRECTLY .jasper FILE AND SKIP THIS STEP)
JasperReport jasperReport = ....
....
....

//STEP 2: FILL REPORT
JasperPrint jasperPrint = ....
....
....

//STEP 3: EXPORT REPORT AND PUT INTO SERVLETOUTPUTSTREAM

JRAbstractExporter exporter = JRPdfExporter();
Map<JRExporterParameter, Object> parameterExport = new HashMap<JRExporterParameter, Object>();
parameterExport.put((JRExporterParameter.JASPER_PRINT, jasperPrint);
parameterExport.put((JRPdfExporterParameter.OUTPUT_STREAM,out);
exporter.setParameters(parameterExport):
exporter.exportReport();

out.flush();


go to http://sourceforge.net/projects/jasperreports/files/jasperreports and download jasperreports-3.7.1-project.tar.gz Project Source Files ... look for demo/samples or demo/samples/webapp ... u can find more example!!
Regards
link publish delete flag offensive edit

answered 2010-02-03 21:12:49 +0800

PeterKuo gravatar image PeterKuo
481 2

@smigol
Thanks for your info.
I added a hyperlink to this thread in http://docs.zkoss.org/wiki/Report_with_ZK_Jasperreport_Component

link publish delete flag offensive edit

answered 2010-02-04 03:36:57 +0800

xmedeko gravatar image xmedeko
1031 1 16
http://xmedeko.blogspot.c...

@PeterKou FYI, I have opened this thread again, because it is linked from http://docs.zkoss.org/wiki/Jasper. (Although the link is old, I will update it).

link publish delete flag offensive edit

answered 2010-07-23 04:08:07 +0800

RFSLUX gravatar image RFSLUX
75

Hi smigol,

th@nx for your post. This morning I start to integrate jasper in our project and your post helps me a lot !
Only two hints from me, which costs me a little time, and may help anyone.....

I use iReport 3.7.4 to design and compile the reportfile.
The following code:

JasperPrint jasperPrint = JasperFillManager.fillReport(session.getWebApp().getRealPath("/WEB-INF/jasper/report3.jasper"), new HashMap(),source);

Only gets exception: net.sf.jasperreports.engine.JRRuntimeException: Unknown hyperlink target 0
Using zk5.03PE

Problem seems: compability issue
If there are compability problems with compiled files and jasper-lib the save way is to compile at runtime.

To compile at runtime I need Apache commons-beanutils-.jar and commons-digester.jar to add to WEB-INF/lib
@ZK-Team: Maybe an idea to add this to zkpe-bin-5.0.3\dist\lib\ext ???

Best regards,
Jörg

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2008-11-05 22:21:30 +0800

Seen: 6,948 times

Last updated: May 05 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More