Home
Analytics
Displaying watermark image conditionally Birt 2.5
Megha Nidhi Dahal
Hi,
I'm using BIRT 2.5. I have a requirement where in a watermark image has to be displayed only for Draft/Test reports.
In my approach, I have passed a parameter from code which gives me the url of Background image ("bgimage").
Then I have written a script for a grid inside the master page as:
onPrepare
this.getParent().getStyle().backgroundImage = params["bgimage"];
I have checked with my colleagues, it works fine with older versions, but I get a null pointer exception when the url is not passed, i.e if the report is not test report, I get a null pointer exception.
Need Help.
Thanks in advance.
Arpan
Find more posts tagged with
Comments
mwilliams
Hi Arpan,
Are you saying that if you pass a null value for the background image, you get an error? Or something else?
Megha Nidhi Dahal
Hi Michael,
I don't pass any parameters if the report is not a draft report. Moreover the parameter "bgimage" which I mentioned is a non mandatory parameter.
So, for draft reports I have a valid url passed whereas for non draft reports I do not pass anything.
In this case I get a NullPointerException, see the attachment for further information.
Thanks for your response.
regards
Arpan
Megha Nidhi Dahal
Hi Michael,
In straight forward words, yes.
When that parameter value is null, I get that NullPointerException.
Thanks for your response.
regards
Arpan
mwilliams
Arpan,
I would think a simple solution to this would be to wrap your set background image line with a check for null or give your parameter a default value and check for that. If it's not null or whatever default value you've given it, display the image.
Hope this helps.
Megha Nidhi Dahal
Hi Michael,
I have thought of checking for null initially.
I introduced a check as:
if(params["bgimage"] != null)
this.getParent().getStyle().backGroundImage = params["bgimage"];
But, that didn't work, I was still getting the exception.
Today I introduced a default value for that parameter as "none", so, there will not be null stored at any time in that parameter.
Without the check also, as it would have been:
if(params["bgimage"] != "none")
//set the image
it is working fine now.
So, now I simply write the expression without any condition, i.e.
this.getParent().getStyle().backGroundImage = params["bgimage"];
So params["bgimage"] will have a valid url for testdraft reports and the background image comes up. For non draft reports, params["bgimage"] will be "none" which is invalid url but not null, hence background is not displayed and NullPointerException also is not encountered.
I have tested, it works fine against my expectations of getting FileNot FoundException ("none").
I cannot convince myself that the approach is correct even if it is working fine now.
Please let me know if this approach has some negative consequences.
Thanks a lot again
regards
Arpan
mwilliams
Arpan,
I can't think of anything that would be an issue with that. As long as the error doesn't show up in the report, you should be ok. Not setting the background image if the parameter is equal to "none" would get rid of the error for you though.
Megha Nidhi Dahal
Michael,
It seems I'm out of the trouble now. Thanks a lot.
regards
Arpan
mwilliams
Arpan,
No problem. Glad to help! Let us know whenever you have questions.
Megha Nidhi Dahal
Hi Michael,
Back with an another issue
I'm using Birt 2.5. I have used a big outer list to hold all my palettes and so inside the list I have many other lists, tables and grids.
The design works fine but gives an error while previewing.
It says that list must be able to access one data set.
Is it something that needs to be worried about? I verified that every list has at least one table in it, which access a data set.
Is there any standard thumb rule so that such issues doesn't come up?
regards
Arpan
mwilliams
Arpan,
Is the outer list bound to a dataSet?
kkan
Hi Micheal,
I have a similar problem to the one Arpan mentioned. I am trying to show a watermark 'draft' image. Whilst looking for solutions I found .zip files that resolves the issue however when I applied the same resolution to my BIRT report nothing happened...
The solution I am using is the when report is run as PDF show background image this is in event 'beforeFActory'
This was just added for testing purspose which will later change to check for if the user defined field MFstaus == 'D' then set Background image to draft.
Also another issue I am having is table borders are not appearing in second page..?! strange as i have latest version of BIRT 2.6.2..
can you help as i am tired now of trying/searching for resolutions...
Please find attached a copy of the XML file I using as the source of data plus my BIRT report file
Thanks Kiran
mwilliams
For the border issue, I see what you're saying and it only happens when you have the grouping on the table. If you remove the group, the border shows, so it's like the group header overlaps the main header in the second page. This looks like a bug to me, for sure. As for the background image. I would think that using two masterpages, one with the background and one without, would do it. You could assign the masterpage you want to the first element in the report depending on your condition and that masterpage will be used for all elements unless otherwise specified.
kkan
Hi ,
Thanks for response - I tried the table borders hat worked so thank you! -
with regards to background image I would require the image to appear of every page. would this be possible./. I am new to BIRT and still trying to grasp a lot of things I am to achieve.
Thanks Kiran
kkan
I did create a separate Draft simple master page then
set the page break property 'Master Page' to this page for the first grid in report however only first page had draft image and other element were moved to second pages - which is not what I want...
mwilliams
If I run your report with a new masterpage attached to the first element in the report, it appears for all pages. Can you attach your design?
kkan
Hi Micheal,
As bizarre as this may sound I tried the solution again and it works!!
Thanks for your help
mwilliams
Very weird, but glad it's working now!
Let us know whenever you have questions!