-
1. Re: Seam Reports Jasper and Jboss-javaee6
lightguard Nov 7, 2011 1:10 PM (in response to tophebboy)Try excluding one of the EL libraries, or make the jboss-javaee-6.0 provided scope.
-
2. Re: Seam Reports Jasper and Jboss-javaee6
tophebboy Nov 8, 2011 4:38 AM (in response to tophebboy)
Jason Porter wrote on Nov 07, 2011 13:10:
Try excluding one of the EL libraries, or make the jboss-javaee-6.0 provided scope.Thanks a lot!!!
I excluded el-api from the seam-report-jasper dependancy and now I can deploy it :D!!!!! -
3. Re: Seam Reports Jasper and Jboss-javaee6
tophebboy Nov 8, 2011 10:55 AM (in response to tophebboy)OK.
Now I have another problem. I try to build a report programaticcaly and I have aorg.jboss.seam.reports.exceptions.IllegalReportDataSourceException
when I call
|ReportDefinition::fill(...)|
Here is the class where I try to do that:
"@Inject @Resource("WEB-INF/jasperreports/project.jasper") private InputStream reportJasper; @Inject @Jasper private ReportCompiler reportCompiler; @Inject @Jasper @PDF private ReportRenderer pdfRenderer; // @Inject @Jasper ReportLoader reportLoader; public OutputStream render() { final Report filledReport = this.fillReport(); final OutputStream os = new ByteArrayOutputStream(); try { this.pdfRenderer.render(filledReport, os); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return os; } private Report fillReport() { final ReportDefinition rd = reportLoader.loadReportDefinition(reportJasper); Map parameters = new HashMap(); EntityManager entityManager = dbUtil.getEntityManager(); parameters.put(JRJpaQueryExecuterFactory.PARAMETER_JPA_ENTITY_MANAGER, entityManager); parameters.put("PROJECT_ID", "1"); return rd.fill(entityManager, parameters); }"
Do you have an idea of what I did wrong???
-
4. Re: Seam Reports Jasper and Jboss-javaee6
tophebboy Nov 8, 2011 10:56 AM (in response to tophebboy)For info I called the report via a small java program with the same parameters and it worked...
-
5. Re: Seam Reports Jasper and Jboss-javaee6
tophebboy Nov 8, 2011 11:06 AM (in response to tophebboy)I debugged a little further and I saw that at some point the framework tried to cast my datasource to a JRDataSource.
And it cannot work because I pass it my application EntityManager and, thus, the datasource is a TransactionScopedEntityManager.
How can I manage to give it a suitable datasource?Thanks in advance :)!!!
-
6. Re: Seam Reports Jasper and Jboss-javaee6
lightguard Nov 8, 2011 12:39 PM (in response to tophebboy)You'll have to look at the JasperReports classes and find an instance of JRDataSource which will work for you, create that and pass that in.
-
7. Re: Seam Reports Jasper and Jboss-javaee6
tophebboy Nov 9, 2011 3:57 AM (in response to tophebboy)I understood that :) But I really don't see how to build an appropriate JRDatasource which would encapsulate my EntityManager (since I don't want to pass any query via java, all queries are included in the reports and subreports. I only give the entry point report a paramater which is an id).
-
8. Re: Seam Reports Jasper and Jboss-javaee6
tophebboy Nov 9, 2011 12:17 PM (in response to tophebboy)OK I tried another way. I made something like this:
`Map parameters = new HashMap();
EntityManager entityManager = dbUtil.getEntityManager();
parameters.put(JRJpaQueryExecuterFactory.PARAMETER_JPA_ENTITY_MANAGER, entityManager);
parameters.put("USECASE_ID", "6");
try {
JasperExportManager.exportReportToPdf(fillReport);
byte[] runReportToPdf = JasperRunManager.runReportToPdf(
reportJasper, parameters);
reportJasper.close();
final ByteArrayOutputStream os = new ByteArrayOutputStream();
os.write(runReportToPdf);
return os;
} catch (JRException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}`
But it seems that the report is not filled. I mean I have several logs like:
`18:07:18,903 INFO [STDOUT] DEBUG 09-11 18:07:18,902 (JRBaseFiller.java:fill:883) -Fill 386453935: filling report
18:07:18,906 INFO [STDOUT] DEBUG 09-11 18:07:18,905 (JRFillDataset.java:createQueryDatasource:677) -Fill 386453935: Creating sql query executer
18:07:18,909 INFO [STDOUT] WARN 09-11 18:07:18,908 (JRJdbcQueryExecuter.java:<init>:109) -The supplied java.sql.Connection object is null.
18:07:18,912 INFO [STDOUT] DEBUG 09-11 18:07:18,910 (JRJdbcQueryExecuter.java:createStatement:183) -SQL query string: SELECT * FROM usecase_description where usecase_ID = ?
18:07:18,920 INFO [STDOUT] DEBUG 09-11 18:07:18,913 (JRVerticalFiller.java:fillReport:141) -Fill 386453935: no data
18:07:18,922 INFO [STDOUT] DEBUG 09-11 18:07:18,921 (JRVerticalFiller.java:fillReport:217) -Fill 386453935: no pages
18:07:18,924 INFO [STDOUT] DEBUG 09-11 18:07:18,923 (JRBaseFiller.java:fill:956) - Fill 386453935: ended `
It's like the paramater called USECASE_ID is not passed to the report . And i'm sure of the paramater name and the data with its value set to 6 (running the report with iReport and this parameter leads to a correct result). And the EntityManager I use must be correct because it is used in the whole application
Any idea?? -
9. Re: Seam Reports Jasper and Jboss-javaee6
gastaldi Nov 11, 2011 8:08 AM (in response to tophebboy)You must use net.sf.jasperreports.engine.data.JRJpaDataSource as the JRDataSource parameter in ReportDefinition.fill() method. The rest of the code looks ok.
-
10. Re: Seam Reports Jasper and Jboss-javaee6
tophebboy Nov 14, 2011 5:34 AM (in response to tophebboy)
George Gastaldi wrote on Nov 11, 2011 08:08:
You must use net.sf.jasperreports.engine.data.JRJpaDataSource as the JRDataSource parameter in ReportDefinition.fill() method. The rest of the code looks ok.OK, I see :)
But how do I instantiate a correct JRDataSource starting from an EntityManager, or a standart datasource which I also have? Cause I tried something like this:Report filled = loadReportDefinition.fill(dbUtil.getDataSource(), parameters);
And I have an InvalidDataSourceException. So i'm pretty sure I should have a SeamJasper specific encapsulation of my datasource here but I don't know how to build it :-(
I tried to inject a JRDataSource but it seams the framework cannot inject (I have a missing dependancy exception at deployment).
Searching on the web, I found this:
https://gist.github.com/969969
They use a SeamReportDataSource which seems to fit the need, but I cannot find it in seam-reports-api neither in seam-reports-jasper :-(... -
11. Re: Seam Reports Jasper and Jboss-javaee6
tophebboy Nov 14, 2011 11:28 AM (in response to tophebboy)OK. I succeeded into making it work. I mean at least being able to generate locally a pdf for tests.
I made it like this:Map parameters = new HashMap(); EntityManager entityManager = dbUtil.getEntityManager(); parameters.put(JRJpaQueryExecuterFactory.PARAMETER_JPA_ENTITY_MANAGER, entityManager); parameters.put(JRParameter.REPORT_CONNECTION, dbUtil.getConnection()); parameters.put("USECASE_ID", "6"); parameters.put("TITLE_LEVEL", 0); JasperReport compiledReport = JasperCompileManager .compileReport(reportTemplate); JasperPrint fillReport = JasperFillManager.fillReport( compiledReport, parameters, dbUtil.getConnection()); //For test JasperExportManager.exportReportToPdfFile(fillReport, "C:\\Users\\test\\report.pdf");
:)
-
12. Re: Seam Reports Jasper and Jboss-javaee6
lightguard Nov 14, 2011 12:45 PM (in response to tophebboy)Glad you found something that worked. As far as injection, no, you won't be able to inject them because the Jasper jar isn't a Bean Archive as it doesn't have a beans.xml. You'd need to create a producer for it. I wonder if there's value in adding a wrapper in Seam Reports.