2001 JI Open Discussion Posted August 15, 2006 Share Posted August 15, 2006 By: Yong Wang - wymz Custom data source (sample) question 2002-08-06 13:58Hi, I am trying to use the custom data source as shown in the sample jasper report under datasource directory. I want jasper to generate the report even when there is no data record at all in which case, header and footer should still be displayed. However if I set the data[][] (in the sample code) to empty, even though it still produces a PDF file, the reader outputs an error: "There was an error opening this document. This file cannot be opened because it has no pages" Does anyone know how to fix this? Thanks. By: Teodor Danciu - teodord RE: Custom data source (sample) question 2002-08-07 00:27 Hi, This issue has been discussed several times before on this forum. Since everybody would have a different expectation about what to display in the report when the data source is empty, the most flexible solution is to not display anything at all. Because in this case people would have the possibility to verify that their document was empty due to missing data before displaying it, and they can switch and display some other special document of their choice, suited for the situation encountered. In your case, instead of using that empty data set, you could launch your report using the JREmptyDataSource with one record in it: new JREmptyDataSource(1) See those threads for details about the problem: http://sourceforge.net/forum/message.php?msg_id=1584826 http://sourceforge.net/forum/message.php?msg_id=1600721 http://sourceforge.net/forum/message.php?msg_id=1615841 I hope this helps, Teodor By: Bernd Proissl - berndproissl RE: Custom data source (sample) question 2002-08-07 01:39Teodor, I'd love to see a default behaviour with an empty page (only static text and graphic elements from the XML definition, all fields empty). This is more end user friendly than throwing/displaying an exception. The end user does not know whether the exception comes from 'no data' or from a problem inside the application, but an empty page is a good visual feedback for 'no data'. This default could be enhanced by any application which needs to have another way of handling 'no data' by the ways you desribed. Bernd By: Yong Wang - wymz RE: Custom data source (sample) question 2002-08-07 06:48Teodor, I agree with Bernd on this subject. In many real world scenarios, when the data set is empty, an empty report still should be generated. I don't see any harm in making this a default behavior while doing so makes it more convenient for programming because otherwise you would be required to test the data set before calling fillReport but in some cases, custom data source is generated on fly which would make it even harder to test. Regards, ---Yong By: Yong Wang - wymz RE: Custom data source (sample) question 2002-08-14 07:48I think I am running into a brick wall on this one. If I use JREmptyDataSource(1), I would get a report with one row on there and all fields with null value. This is not exactly what I want. I want to see an empty report with no row on it when datasource is empty. So I tried JREmptyDataSource(0) and again I got the same exception when I try to view the .jrprint file: [java] dori.jasper.engine.JRException: Invalid page index : 0 of 0 [java] at dori.jasper.engine.print.JRPrinterAWT.printPageToImage (JRPrinterAWT.java:223) [java] at dori.jasper.engine.print.JRPrinterAWT.printPageTomage(JRPrinterAWT.java:107) [java] at dori.jasper.engine.JasperPrintManager.printPageToImage(JasperPrintManager.java:438) ... Can someone let me know whether it is doable in jasper or not? I would appreciate any hint on this. By: Teodor Danciu - teodord RE: Custom data source (sample) question 2002-08-14 08:19 Hi, Lets just say that what you want is not possible for the moment in JasperReports. And now let us move forward and explain a little why it is not possible. In the current version, if the data source is empty (no rows), the report generation produces an empty document (no pages), and therefore you catch that error when trying to view it. Some users have proposed that we produce an empty document that will contain at least one page, but nothing will get printed on it, just to avoid such unwanted exception when viewing them. I tend to agree with them and I'm planning to move in this direction. This way would still be possible for someone to test if the document is empty. He or she would just have to test the number of pages and if it is equal to 1, proceed with testing the number of elements on this page. If this is 0 (zero), then the document is empty, most probably due to missing data in the data source supplied. In your case, the difficulty comes from the fact that if you don't want to have such an empty document, but rather a document in which you could still see some sections, there is now way telling what sections should we print and what information they should display. Should we print also the group headers and footers for all the groups defined on the report? What about totals that sum up values at page or group level. Of course, you can say YES, this is exactly what I want and I'm sure you're entitled to say that. But what about the others that would say, NO, I don't want to waste paper printing such meaningless documents. They would want to be able to test if the generated document is worth printing or not. If we already added some graphical elements on that document, there is no way telling it is an empty document anymore. Lets here what others have to say about this. Thank you, Teodor By: Yong Wang - wymz RE: Custom data source (sample) question 2002-08-14 09:12 teodord, I see where you are coming from. Pardon me, I don't know how jasper is implemented and how this behavior fits in the overall picture. But if the change of this behavir doesn't impact the overall architecture, could it be possible that you add an option method to JasperFillManager to allow users to control this behavior. This way everyone get what they want and no flexibility is lost. There are two users (me included :) in this thread want to see it implemented differently. I wonder how other users will see this issue and vote on it if they don't read all posts. Regards, Yong Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now