Wednesday, June 1, 2011

BIRT report conditional watermark: My fight with the NullPointerException

Hello All,

The first thing I ever did with BIRT was to develop a report from a fairly simple data set. And, there was a very simple requirement of displaying a TEST watermark if the report was a draft.

To accommodate this change, there was a simple change in the designer where, I had to insert one string type report parameter bgImage which would have the url of the TEST image file for draft report and nothing for actual report. Also, in the onPrepare method of any palette inside the master page, the following script had to be inserted:
this.getParent().getStyle().backgroundImage = params["bgImage"];

This worked fine for every draft report and naturally I was very happy to have figured it out so soon. But, when I finally tried generating an actual report, BIRT failed with a NullPointerException. Since the report was running all right before this change, the primary suspect was the inserted script, and as everybody would have done, I included a check in the script as:
if(params["bgImage"] != null || params["bgImage"] != "")
this.getParent().getStyle().backgroundImage = params["bgImage"];

Somehow even this didn't seemed to work out. Frustrated and irritated, I had only one place to look back to, the BIRT exchange forum. Got some valuable suggestions from experts, but somehow I was unable to come out of this. Then, I thought of giving this report parameter(bgImage) a default value like none or junk and then try out. To play safe, the check was still used otherwise I suspected that BIRT might throw FileNotFound or something similar. Hence, my new script looked like:
if(params["bgImage"] != null && params["bgImage"] != "junk" || params["bgImage"] != "none")
this.getParent().getStyle().backgroundImage = params["bgImage"];

And voila!!! The report ran successfully for both draft and actual reports with expected output and watermarks where needed.

Since, this thing was working, I never bothered to modify the script. But just out of curiosity, one fine day I removed the check, now my script looked like the initial one:
this.getParent().getStyle().backgroundImage = params["bgImage"];
The only change that has happened till now was, that I gave the parameter a default junk value.

To my surprise, the report ran successfully for draft as well as actual. Watermark was appropriately applied. Till date I'm unable to draw a conclusion as why the NullPointerException, but I have maintained it as a thumb rule to always specify default value for nullable url parameters.

The report is running fine till date :) :)

And I finally won the fight with the all times champion NullPointerException

Follow this link http://www.birt-exchange.org/org/forum/index.php/topic/19303-displaying-watermark-image-conditionally-birt-2-5/page__pid__63748__st__0 for more information on this topic.

Disclaimer: This is 100% personal opinion. If it contradicts in any means, the writer requests to be informed.

Monday, December 13, 2010

BIRTing all the way

Until recently I was using BIRT 2.5.1. There were no any issues with 2.5.1 that I faced except for one.
One of the reports that I designed had to support normally 100K+ rows. We know excel 2003 cannot display more than 64k rows. Well I could see some care taken to this fact by the xls emitter as it was trying to split the excess records into a new sheet, but it wasn't able to do it successfully.
The generated file wouldn't open up in excel. Upon referring to the error log file, I came to know that some tags in the xml file (the xls output) were not closed properly. These tags were workbook, worksheets, etc... The next obvious thing I could do was to manually close these incomplete tags and see what the output looked like. Yes the output had excess rows in a new sheet, however some of the records after 64k th record were not written in the file. In short, some records also were missing along with the missed tags.
Upon valuable advices from BIRT Gurus in the forum, I decided to upgrade to BIRT 2.6.0.
With the same test data and a slight modification in the report engine instantiation code, i.e. a very specific emitter for xls EXCELEmitter is available which can be used, I could see the report coming up beautifully on as many sheets required. There were no missing tags and the output had all the rows as that in source.

Though this problem was solved, there were slight changes in the font sizes. Small/Medium/Large... in BIRT 2.5.1 and BIRT 2.6.0 interpret different sizes. If it is intended to preserve the same formatting for a design that could be run in different or later versions of BIRT, I would suggest to use specific sizes like 8pts/10pts... instead of Large/Medium..

Still there is one more feature that is very much requested in later versions of BIRT, at least from my angle. This feature is to be able to explicitly instruct BIRT to split its xls output in multiple sheets and also a support for xlsx format.
I have requested for an enhancement in the eclipse community for this.
Please follow this link to review and vote for this enhancement click here

Any queries please leave a comment.

Disclaimer: This is 100% personal opinion. If it contradicts in any means, the writer requests to be informed.

Wednesday, September 30, 2009

Thursday, September 24, 2009

Google Profile

Check out my google profile.
Follow this link:
http://www.google.com/profiles/arpandahal
in reference to:
"Megha Nidhi Dahal"
- Megha Nidhi Dahal - Google Profile (view on Google Sidewiki)

Picasa is cool

Picasa web album is really cool.
Got a first hand to it, I suggest all of you to try it out.

in reference to: Picasa Web Albums - arpandahal (view on Google Sidewiki)

My First Blog

Hi, just opened this account.

Request all to kindly post some suggestions to help me improve my blog.


Also check out my site here.

Megha Nidhi Dahal's Webpage