Friday, May 23, 2008

Report Empty (Blank page is displayed) When No Data is present/retrieved: Solution


A Common Problem arising in Jasper Reports is when there’s no data retrieved A blank (white) page is displayed. This can be corrected in two ways

The Easiest way is of course to correct it through iReport. Find out how to do it by reading this.

There’s another not-so-subtle way to do it. That is setting the option through Java Code.

Whatever the method we use to display our report, we would have to construct the JasperReport objet. Simply set the option like this:

JasperReport jasperReport = (JasperReport) JRLoader.loadObject(jasperTemplateURL);

jasperReport.setWhenNoDataType(jasperReport.WHEN_NO_DATA_TYPE_ALL_SECTIONS_NO_DETAIL);

The Method setWhenNoDataType can be set three values. All Three are Constants in the JasperReport Object.

  • jasperReport.WHEN_NO_DATA_TYPE_BLANK_PAGE
  • jasperReport.WHEN_NO_DATA_TYPE_NO_PAGES
  • jasperReport .WHEN_NO_DATA_TYPE_ALL_SECTIONS_NO_DETAIL

We can use them to set it to any of the options we want.

31 comments:

Anonymous said...

perfect answer, thank you

Anonymous said...

Hi.

I am not yet try your solution for empty record..However, your post about this topic was clear than other (in google).

If i my problem solve, I will inform here.

Azizi Yazit.

Anonymous said...

at last..The problem that disturb me all the time (klien dont want a blank page) has solved by this simple but clear post!

Thanks!

Azizi Yazit
Technologist

Unknown said...

Hi
I am having problem in displaying result from jasper reports in IE browser.the same thing is working in firefox and google chrome.can you help regarding this.thank you in advance

Acromantula said...

Hu Vijay,

cant say i ever came accorss an issue like that..


*****
FYI... in the future when ur asking for help always better if u give background information (I wouldnt hv being able to help u any way on this issue..)

eg.
IE-- What IE version?

What version of jasperReports you're using
How do u send the information from the Back end to the front end. etc etc etc.

Unknown said...

Hi Acromantula
i am sorry for that.I am using IE 7.same functionality is working in fire fox 3.5.3 and even in chrome 3.0.195.27.My problem is when i click on button to get the report i am getting blank page when data is there otherwise getting Internet Explorer cannot display the webpage.

if any help will be thank full to you

Unknown said...

Hi
I have solved the problem that is related to response.setHeader in my serlvet.earlier i had

(code)response.setHeader("Cache-Control", "no-cache");(code)
then i added thisline(code)response.setHeader("Cache-Control", "cache, must-revalidate");(code)
now it is working fine
thank you.

venugopal bodapati said...

how to send page wise totals to last page in irport

Unknown said...

Hi All,
I had a problem in with jasper reports. When I have chart in my report it's showing only blank page. When I tried to export as PDF I'm able to see charts in it but when I export to HTML I'm seeing only blank page.
Looking at your post I think you would be able to help me.

vignesh2k9 said...

is it anyway to add " No Records Found " when do data record found

guides costarica said...

this site is excellent and the guides are excellent throughout the network sought and none had information that this site has enabled me congratulate very good information is very varied and interesting is great.

Anonymous said...

Perfect, my problem solve.
Thank you.

Darkmolo said...

Hello,
Actually i jave faced the same problem, i hope this can be helpful, i do this to avoid the emtpy report:
---------------------------------
JasperPrint jasperPrint = JasperFillManager.fillReport(
jasperInputStream,
parameters,
new JREmptyDataSource());
---------------------------------

The "new JREmptyDataSource()" is the key.

Anonymous said...

Hi,

Now i am generating jasper repots using ireport.
I am passing data collection from java to jrxml.
if the datasource is empty it returns the blank report.Insted of the i need to display "no records found" message please hep me on this.

Anonymous said...

gRACIAS!

Anonymous said...

Darkmolo's solution works fine for me
thank you very much

Anonymous said...

can any body please tell me how to pass one sub report page number to other sub report

I have 3 sub reports in one main report. i want to display page numbers continuously...

Thank you

atisun said...

Vijay Kumar : if IE doesnt work properly, try this..
response.setContentType("application/x-msdownload");

when i set content type to x-download, it works for firefox, chrome etc but not for IE. after changing it to "x-msdownload" it works every browsers.

I hate IE, its not programmer friendly..

Anonymous said...

Excelente muy buen aporte para un blog Geek DistroGeek

Anonymous said...

Excelent , very good contribution for a Geek blog...

Anonymous said...

In Ireport, when I click "Preview" for an empty reports, it opens a dialog with "The document as no page". When I click on OK, an empty file opens up...

Anonymous said...

please i have a probleme with jasperserver i create a report then i include a jrxml file but when i want to execute an sql statement in the report to have a specific report in a extended date i dont have any report coming out ?!

Cristian Daniel Ortiz Cuellar said...

i support the comment of Darkmolo. in case you are receiving a empty record try to use ew JREmptyDataSource() see his comment above... it works for me..

Anonymous said...

Hi...I had this problem too, and I used the option when no data- print section but no data, However this is working only with sections with no overflow support and detail band sections do not get printed. Any work around???

chandu(chanaiah.k) said...

FF is displaying after page number in jasper reports generated text file.how we resolve.

Unknown said...

hi
i have i am using jasper irreport 5.6.0 and i have created the design and the query is working fine, i am able to preview my data at the jasper but when i tried it using my java code i have this popup the document has no pages...please help

Anonymous said...

Solved.
Thanks.

Anonymous said...

Hello Everyone ,

I am trying to print data in to the pdf format using jasper report 5.6 from the database,
data start from second page first page is blank only header part is there .
please help me i want to print data from first page..
Thank you in advance.....

Anonymous said...

Jagadish:- I am trying to print data in to the pdf format using jasper report 5.6 but first designed main page coming properly but unnecessary 2 more page's coming with lines
how to prevent that 2 more pages to display there

Funny Inspirational Quotes said...

Very nice post, thank you for sharing

Anonymous said...

Thanks alot Darkmolo ..You saved my day.
Have spend one full day to avoid blank page.
Thanks alot

Post a Comment