Home
Analytics
Writting scripts in beforeFactory,onCreate and onRender using Birt api using java code.
ravi11
<p>Hi,</p><p> </p><p>I am trying to write scripts for a report for layout and table so by using BIRT api,but I am not able to find where to add scripts for a table content. Can anyone help me how to write scripts for a table data scripts on render or on create. It would be helpful if anyone send me a sample java code for this.</p><p> </p><p>Thanks,</p><p>Ravi</p>
Find more posts tagged with
Comments
pricher
<p>Hi Ravi,</p><p> </p><p>I think you may find this video helpful for understanding the basics of scripting with BIRT: <a data-ipb='nomediaparse' href='
http://www.youtube.com/watch?v=FQ9VjByPNWM'>http://www.youtube.com/watch?v=FQ9VjByPNWM</a></p><p> </p><p>Regards,</p><p> </p><p>P.</p>
ravi11
<p>Hi,</p><p> </p><p>Thanks for your post,but my problem is not with undersating those onCreate or onRender.</p><p> </p><p>All i need a way to apply the scripts written by me in rptdesign file into a java code which generated rpt design file by using birt api engine.</p><p> </p><p>I need a class or method where i can place the scripts to get a desired rptdesign file with the java code.</p>
pricher
<p>Hi,</p><p> </p><p>Sorry for misunderstanding your initial question. I am no expert writing Java code using the BIRT API, but I was able to add some JavaScript to the onCreate event of a table by using the following three lines of code:</p><p> </p><p> TableHandle table = elementFactory.newTableItem(null, 3, 1, 1, 1); // Create a table
table.setOnCreate("alert('Hi there');"); // Add script to the onCreate event of the table
design.getBody().add(table); // Add the table to the rptdesign</p><p> </p><p>I have attached the full source code.</p><p> </p><p>Hope this helps,</p><p> </p><p>P.
</p><p> </p>
ravi11
<p>Hi,</p><p> </p><p>Thank you very much for the code. It helped me a lot.</p><p> </p><p>I just want to get some more doubts clarified. All i need is to put a note or legend in master page footer,can you help me in writing scripts for that.</p><p> </p><p>My requirement is like this.</p><p> </p><p><strong>Page 1</strong></p><p>
</p><p><strong>Table</strong></p><p>Name Value</p><p>A 99</p><p>B 10p</p><p>C 100e</p><p>D 88</p><p><strong>Footer</strong>:</p><p>e - means excellent</p><p>p - means poor</p><p>
</p><p> </p><p> </p><p><strong>Page 2</strong></p><p>
</p><p><strong>Table</strong></p><p>Name Value</p><p>E 99</p><p>F 10</p><p>G 100e</p><p>H 88</p><p><strong>Footer</strong>:</p><p>e - means excellent </p><p> </p><p>
</p><p> </p><p>Here based on the content of the page I should show only the foot notes which are present in that particular page as shown above.</p><p> </p><p>Please help me to achieve this. I had tried setting variable and adding page variables in the master page footer,but it had not worked as I expected. Please ask me if you have not understood my question. If you can send me a sample rptdesign it would be helpful for me. </p><p> </p><p>Thanks,</p><p>Ravi.</p>
pricher
<p>Hi,</p><p> </p><p>Attached is a report design that should work for your case. It's using Page Variables and some scripting to dynamically create a footer based on data in the table.</p><p> </p><p>I am using Classic Models to display CUSTOMERNUMBER, CUSTOMERNAME and COUNTRY. For countries UK and USA, I display a legend in the footer, only if these 2 countries are shown on the page.</p><p> </p><p>The two page variables, <strong>isUSA </strong>and <strong>isUK </strong>are initialized on the <strong>onPageStart </strong>event of the report. On the <strong>onPageBreak </strong>event of data item COUNTRY, I set the value of the page variables if the value of COUNTRY is either USA or UK.</p><p> </p><p>On the footer of the master page, I display the two page variables in a grid.</p><p> </p><p>The example is a bit rough and could probably be improved, but it should give a good start.</p><p> </p><p>P.</p>
ravi11
<p>Hi,</p><p> </p><p>I had tried this approach before. but If you notice it closely,the data is not reflecting from the page.</p><p> </p><p>The page is not showing data in first page even it contains USA. Is this same on your end also?</p><p> </p><p>Page 1 has USA but it is not showing it in the footer. Instead default value false is getting displayed.</p><p> </p><p>Page 2 the previously added USA from page 1 is getting printed in Page 2 footer.</p><p> </p><p>Thanks,</p><p>Ravi.</p>
pricher
<p>Which version of BIRT are you using? I have attached a PDF output of the design I sent you and you can see it works perfectly.</p><p> </p><p>Strange...</p>
ravi11
<p>Hi,</p><p> </p><p>May be the version is the problem in this case. I am using Eclipse BIRT Designer Version 4.2.2.v201301221637</p><p> </p><p>Thanks,</p><p>Ravi</p>
pricher
<p>I get it. You are probably outputting directly to PDF, aren't you? When I generate the report directly to PDF, the footers are not updated correctly; they are one page behind, like you are describing. However, if I generate to the BIRT Web Viewer, it works fine. And if I generate the PDF from the BIRT Viewer, it is fine as well.</p><p> </p><p>Can you test on your side?</p>
ravi11
<p>Hi pricher,</p><p> </p><p>Yes I am generating pdf directly in eclipse run as pdf. I tried updating eclipse to luna and kelper as well. I also changed the version of BIRT to latest one,but nothing worked for me. Can you please help me in resolving this issue. How to generate in BIRT Web Viewer?</p><p> </p><p>Thanks,</p><p>Ravi.</p>
ravi11
<p>Hi pricher,</p><p> </p><p>Thanks for your reply,yes its working in run as birt viewer. I had seen this in using Birt viewer toolkit. But I need it to run in pdf file as well.</p><p> </p><p>Please help me in this.</p><p> </p><p>Thanks,</p><p>Ravi.</p>
pricher
<p>Hi Ravi,</p><p> </p><p>I'm afraid this looks like a bug in the PDF emitter. I cannot be of much more help at this point.</p><p> </p><p>P.</p>
pricher
<p>One thing I would like to add: In my tests, outputting directly to PDF works fine using the runtime BIRT Viewer or BIRT Viewer Toolkit. In other words, if I use the following URL:</p><p> </p><p><a data-ipb='nomediaparse' href='
http://localhost:8700/birt/frameset?__report=report/Dynamic Footer.rptdesign&__format=pdf'>http://localhost:8700/birt/frameset?__report=report/Dynamic Footer.rptdesign&__format=pdf</a></p><p> </p><p>it
works fine.</p><p> </p><p>P.</p>
ravi11
<p>Hi pricher,</p><p> </p><p>Yes the url you sent is working but that doesnt fullfill my requirement as I am trying to get the pdf as output by using PDFRenderOption class.</p><p> </p><p>Please help me. Is there any way to get the desired output without using Birt report Viewer. If not possible can you help me how I can add Birt report Viewer in to my project?</p><p> </p><p>Thanks,</p><p>Ravi.</p>
ravi11
<p>hi pricher,</p><p> </p><p>Do we need to report this bug anywhere? Can i know when this bug will be fixed or any alternate solution?</p><p> </p><p>Thanks,</p><p>Ravi.</p>
pricher
<p>Hi,</p><p> </p><p>You can enter a bug for BIRT Open Source at the following address: <a data-ipb='nomediaparse' href='
http://eclipse.org/birt/community/#bugzilla'>http://eclipse.org/birt/community/#bugzilla</a></p><p> </p><p>Regards,</p><p> </p><p>P.</p>
;
ravi11
<p>Hi pricher,</p>
<p> </p>
<p>I had Raised this bug in bugzilla,but the issue is not rectified yet. Can you tell me when this problem can be resolved or can you report this bug to your team so that it gets solved faster.</p>
<p> </p>
<p>Thanks,</p>
<p>Ravi.</p>