What exactly would you like to achieve - downloading reports (and in which format) or embedding reports on pages with Vaadin components.
If you would like to let the users download PDF reports, you should be able to generate the reports with JasperExportManager. If the reports are not too big, you can even export them to an in-memory byte and serve them directly from it.
Some options:
To create a download link from a page where the report is generated, use the Link component (see e.g.
this forum post ). See also the different types of
Resources provided by Vaadin.
To embed reports inside an application, you can take a look at the
Embedded component. There is also an example on the first page linked above.
Creating a permanent download URL for dynamically generated content requires the use of a URIHandler. See
the book for a window-level URIHandler (preferred) or
this forum post if you need to handle it on the application level.
Disclaimer: I have not used JasperReports myself, just took a look at its API.
StreamResource.StreamSource source = new StreamResource.StreamSource() {
public InputStream getStream() {
byte[] b = null;
try {
b = JasperRunManager.runReportToPdf(getClass().getClassLoader().getResourceAsStream("reports/TokenReport.jasper"), map, con);
//
//
//
What is map and con?
What about using dynamicreports ?
I have a issue with Jasper and Vaadin while generating HTML Report.
Code sample:
JasperPrint print = JasperFillManager.fillReport(report, parameter, ds);
JRHtmlExporter exporter = new JRHtmlExporter();
final ByteArrayOutputStream output=new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,output);
exporter.exportReport();
output.flush();
StreamResource.StreamSource source = new StreamResource.StreamSource() {
public InputStream getStream() {
byte[] b = null;
b=output.toByteArray();
return new ByteArrayInputStream(b);
}
};
StreamResource resource = new StreamResource(source, "TestReport.html", application);
When Jasper generating HTML report it is use an empty images tags for width and space formatting and in result HTML we have a lot of empty images like:
I try this in servlet and it is works prefectly, but in Vaadin application image uri is - <APP_Name>/APP/1/image?image=px
and In result I see “image not found” in all positions where empty images is presented.
I try to add in Servlet environment:
Im new to vaadin… I have been using vaadin last one month… i need one help… in my application it needs to generate jasper report… i read your forum… and tried code that you provided but for me its not working… can you give full source code and instructions for generating report…can you help me… Im awaiting for reply soon…
at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2266)
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2279)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2750)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:780)
at java.io.ObjectInputStream.(ObjectInputStream.java:280)
at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.(ContextClassLoaderObjectInputStream.java:56)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:195)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:361)
at net.sf.jasperreports.engine.JasperRunManager.runReportToPdf(JasperRunManager.java:242)
at com.vaadin.cmms.utility.CmmsUtility$2.getStream(CmmsUtility.java:202)
at com.vaadin.terminal.StreamResource.getStream(StreamResource.java:167)
at com.vaadin.Application.handleURI(Application.java:801)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
Here’s your problem : I am assuming that build\web is the root of the web application. In this case, web/pdfcreator/faultreportx.jasper is not on the classpath. web/WEB-INF/classes (and web/WEB-INF/lib/*.jar) are on the classpath, but the root of the web application is not.
I, personally, would split things out a little, something like this (not typed in IDE, not tested, probably won’t compile!):
InputStream reportInputStream = getClass().getClassLoader().getResourceAsStream("pdfcreator/faultreportx.jasper");
if(reportInputStream == null){
throw new RuntimeException("Could not find report source");
}
JasperRunManager.runReportToPdf(reportInputStream, map, connection);
This way you can see what’s failing a little clearer.
(I’d actually split it out into separate methods, probably different classes - but that’s just me!)
I’d then change the build so that the *.jasper files end up in WEB-INF/classes (or in a jar in WEB-INF/lib)
You could access the .jasper file where it is, but you’d need access to the ServletContext IIRC, and that would get even more complex.
Hi,
I want use JasperReports with HTML export to build in Embedded component of vaadin. I can see the html report but I have empty images to fill in spaces. Did you find a solution to fix this problem ?
Hi.
I have a problem with integretion vaadin and jasperreport. I’m using Netbeans 6.9.1. I have Vaadin app and I want to print report. I’ve added jasperreport-4.0.2.jar to my web app libs. I put my code below. Every thing is ok, I can load stream, but I get exception:
final Map paramMap = new HashMap();
paramMap.put("CompanyName", "My Company Inc.");
final Connection con;
FirmaJpaController jpaFirma = new FirmaJpaController();
con = jpaFirma.getEntityManager().unwrap(java.sql.Connection.class);
StreamResource.StreamSource source = new StreamResource.StreamSource() {
public InputStream getStream() {
byte[] b = null;
try {
b = JasperRunManager.runReportToPdf(getClass().getClassLoader().getResourceAsStream("reports/myreport.jasper"), paramMap, con);
} catch (JRException ex) {
Logger.getLogger(ClientMenu.class.getName()).log(Level.SEVERE, null, ex);
}
return new ByteArrayInputStream(b);
}
};
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("reports/myreport.jasper");
StreamResource resource = new StreamResource(source, "myreport_" + System.currentTimeMillis() + ".pdf", getApplication());
getApplication().getMainWindow().open(resource, "_new");
}
I’m newbie in Java. I’m looking forward for replay.
I strongly suspect that jasper reports has more dependencies - in other words, you need to add more to the webapp “lib” directory. For example, I can see that you are trying to export a PDF file, so you will need to add iText-xxx.jar
According to http://www.installationwiki.org/JasperReports (which is a little out of date), it looks like you’ll also need to add commons-beanutils,commons-collections, commons-digester, and commons-logging too. All of those jars should be in the download archive.
Essentially, this is really a Jasper issue - if adding those jars doesn’t work, I’d go and search on the Jasper forums.
Problem solved.
You were right Charles.
I have added all jars files from download archive (*.zip file with Jasper project) to my web app lib folder and now it’s working.
I have another problem.
Im using Vaadin with JasperReport. Every thing works under Windows+NetBeans. But now I want to put my Web Application on Linux Server (Centos 5.5). I’ve installed tomcat6 and my Firebird databese. It works fine, but when I want to print report it fails.
To load *.jasper file Im using method:
static public void PrintReport(final Map paramMap, final String repName){
final Connection con;
FirmaJpaController jpaFirma = new FirmaJpaController();
con = jpaFirma.getEntityManager().unwrap(java.sql.Connection.class);
StreamResource.StreamSource source = new StreamResource.StreamSource() {
public InputStream getStream() {
byte[] b = null;
try {
InputStream rep = app.getContext().getClass().getResourceAsStream(repName.concat(".jasper"));
if (rep!=null) {
JasperReport report = (JasperReport) JRLoader.loadObject(rep);
report.setWhenNoDataType(JasperReport.WHEN_NO_DATA_TYPE_ALL_SECTIONS_NO_DETAIL);
b = JasperRunManager.runReportToPdf(report, paramMap, con);
} else {
app.getMainWindow().showNotification("There is no report file!");
}
} catch (JRException ex) {
Logger.getLogger(MainApp.class.getName()).log(Level.SEVERE, null, ex);
}
return new ByteArrayInputStream(b);
}
};
StreamResource resource = new StreamResource(source, "myreport_" + System.currentTimeMillis() + ".pdf", app);
app.getMainWindow().open(resource, "_new");
}
I don’t know what to do. Im loading my *.war file to linux tomcat6 (there should by all needed libs) and it works but i can’t print any report.
Should I install something on Centos to work with JasperReports ?
well first of all i am not a good programmer but try your netbeans project on a centos installation (netbeans + centos) and see if it works. do you store the files on the filesystem? if yes look at the path’s. good luck
I solve the problem. It was font problem. In my libs I haven’t ArialFont package. It was a little strange because I hadn’t any visible exception. I found it in catalina.log.
hi everyone, i’m new in vaadin. i have a developed an almost complete working application, but no with jasperreport. i have tried to change IDE, container, adding all jasper dependencies, etc, with no result. i also tried to run enterpriseapp add-on on my environment, it’s worked except for report. can anyone publish a simple project / add on that show a worked solution for integrating vaadin & jasper? thanks for your help.