Hi, I’m researching about JasperReports in Vaadin projects. I’ve designed my reports with iReport using elements “Fields”.
Now I’m trying to fill that from Vaadin code, when I click on button.
First I don’t know how to set an Item (from Table) to “Datasource” of the report and also my program execute an exception because it doesn’t found the “.jasper” file, Where I should put this file?
Typically, *.jasper files need to be “on the classpath”. Placing them in the root of WEB-INF/classes would probably be OK.
I’ve not used Jasper & Vaadin together - I don’t see it being that difficult, though. To use a Vaadin table as a Jasper data source, you would probably need to create a Jasper data source that wraps a Vaadin collection.
Here is a starting point
It’d probably be easier, in the first instance, to actually directly connect to the database and execute the query from within the report itself - I imagine there are many articles on the internet showing how to do this. I’d start simple, and work my way up!
To populate the datasource for jasper from table component depends on how you populate the data for table component.
if you populate the data manually using addItem, then you need to iterate the table, get item (create Map) and then put it in the List.
for jasper part, use the JRMapCollectionDataSource or JRArrayCollectionDataSource.
if you populate the data using vaadin container (e.g BeanItemContainer), just send the datasource that you use to fill vaadin container
to jasper. for jasper part use JRBeanCollectionDataSource.
Well, aparentely application found the *.jasper. But now I have an exception in the this line: [code]
[b]
jasperPrint = JasperFillManager.fillReport(reporte, null, new JRBeanCollectionDataSource(listaPariticipantes));
[/b]
[/code]
sep 26, 2012 12:37:04 PM com.vaadin.Application terminalError
Grave: Terminal error:
com.vaadin.event.ListenerMethod$MethodException: Invocation of method buttonClick in com.infosisarg.zeus.web.ui.vaadin.subviews.DetalleArticulo$1 failed.
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:532)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1219)
at com.vaadin.ui.Button.fireClick(Button.java:550)
at com.vaadin.ui.Button.changeVariables(Button.java:217)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.changeVariables(AbstractCommunicationManager.java:1455)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1399)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1318)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:763)
at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:296)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/digester/Rule
at net.sf.jasperreports.components.ComponentsExtensionsRegistryFactory.<clinit>(ComponentsExtensionsRegistryFactory.java:100)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(JRClassLoader.java:157)
at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java:115)
at net.sf.jasperreports.engine.util.ClassUtils.instantiateClass(ClassUtils.java:53)
at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.instantiateRegistry(DefaultExtensionsRegistry.java:237)
at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRegistries(DefaultExtensionsRegistry.java:214)
at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRegistries(DefaultExtensionsRegistry.java:162)
at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getRegistries(DefaultExtensionsRegistry.java:133)
at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:105)
at net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:83)
at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:121)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:88)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:103)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:61)
at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:153)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:82)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:653)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:969)
at com.infosisarg.zeus.web.ui.vaadin.subviews.DetalleArticulo$1.buttonClick(DetalleArticulo.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:512)
... 27 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.digester.Rule
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
... 53 more
I’ve not done it - but yes, theoretically. I’d render the report to PDF and then embedd the PDF via Embedded. You can of course try rendering HTML, but I suspect that pagination & css/images would become an issue.
It does work for me! But, unfortunately the example does not explain the fact that the SQLContainer for the filteringTable (in the UI/View) is not connected in any ways to the resulting Report (PDF, this is done within the jasper template with pure sql). In Other words I would like to know how one can pass the SQLContainer (or filteringTable) to the JasperReports.
In my case, I would like to pass a SQLContainer (according to the selections made in filtertingTable) to jasperReports.
Has anyone tried this? Or tried the suggestion above using this source provided by Charels? http://jasperreports.sourceforge.net/sample.reference/datasource/index.html
Easier way is to retrieve selected (or all) values from table. A table.getValue() would give you a collection that you can use in the jasper report as a parameter. On the jasper side, this parameter should be used in the FROM clause (ie as a IN clause)
Depending on your container’s itemIds, you can have to convert the collection to a true collection of db ids
If you’re not (or do not want to) working with a database, you can create a dataset to use it in the jasper report (it supports XML, JSon, you could probably use also XlsExport add-on), but it seems quite less efficient.
thanks for your reply. I will try your suggestions at some point later. We currently trying a more direct and easier approach for the reporting wihtout jasper reports.