Home
Analytics
BIRT 2.3. External Javascript.
millvall
Hi,
I'm trying to use an external Javascript in a BIRT 2.3 report, but having problems. Are there any examples or documentation how to use an external JS?
Thanks for any directions.
Milt.
I've placed a JS file in the project folder and it's seeable in the Navigator
window. (I assume I should be able to store my JS files in a common folder thus making them available to all report projects.)
When I call a function in the JS file, from Initialize using ECMAscript, two things:
1) I have to use a try block to get it compile.
<script type="text/javascript" src="JSTest.js"></script>
// Line above makes no difference when removed.
fstr = new java.io.FileOutputStream("C:/DebugMilt.txt");
pw = new java.io.PrintWriter(fstr);
pw.println("*Start of Report");
// Call a function in an external Javascript file.
try{
test101();
} catch (err) { pw.println("*ERROR 101 = " + err); }
2) The catch triggers and reports the function not found:
*ERROR 101 = ReferenceError: "test101" is not defined.
Here's the JS:
importPackage( Packages.java.io);
function test101() { }
function wrtInit()
{
var fstr = new java.io.FileOutputStream("C:/debug.txt");
var pw = new java.io.PrintWriter(fstr);
}
function wrt(showThis) { pw.println(showThis); }
function wrtClose() { pw.close(); }
-- eom --
Find more posts tagged with
Comments
mwilliams
Hi Milt,
You should just be able to put the .js file in your resource folder and then add the javascript file in the resources section of the property editor for the report design.
vash
Hi Michael,
I have exactly done as you have mentioned - about including the external javascript into resources.
However, while using the function from the external file - there is no response.
I am attaching my report design and external javascript file.
Its a very - "hello world" like script testing.
In my report design I have two "Click here" links - the first one calls the external function and the second text element uses the 'alert' function internally.
In the preview mode when you click the first 'Click here' - it does not call external 'click_me()' function.
Can you please help look into this.
Thanks,
Vash
vash
Any response for this one?
Thanks,
Vash
johnw
Hey Vash,
Your misunderstanding what the javascript resources are for and the scope of Javascript in BIRT reports. By including a external javascript file from your resources, you are including it for use in server side processing. This means this gets run on the server running BIRT, not in the browser that is viewing a BIRT report. What you are trying to do is include a javascript file client side. In this case, you would copy the JS file somewhere in the BIRT viewer, and use a standard javascript include tag in your HTML text element.
John
xpaterna
Hi,
I have the solution for include an external Javascript!
If I want to include the file "hello.js" I just need to add "<script type="text/javascript" src="birt/hello.js"></script> to the files: RunFragment.jsp, RequesterFragment.jsp and FramesetFragment.jsp.
It rules!
mwilliams
Thanks for the update xpaterna! This could be a good tip to add in the devShare!
srisaibabu
Hi mwilliams,
Using the above mentioned approach by xpaterna, can we configure jQuery library as well.
I tried but couldnt suceed. Any suggestions would be very helpful.
Thanks in advance.
Regards,
Sri Sai
CBR
You should be aware of the fact that there is a client side java script language and a server side java script language. Both languages are not related to each other. So client side and server side javascript is totally different. If you want to include server side java script you can follow instructions of mwialliams.
If you want to include client side javascript it's best to add it to any of the jsp pages of the BIRT Webviewer (as already mentioned by xpaterna)
srisaibabu
Thanks for the reply cbrel.
I have followed the same instructions from the above mail chain but couldn't succeed. Plain HTML page works fine, but when included in a text control, there are no errors nor the desired output in BIRT report.
Please find the attachment. Am trying to simulate List.html output in BIRT report.
Please advise.
Regards,
Sri Sai
mehdiesteghamat
<p>Please let me know how jQuery can be included.</p>
<p> </p>
<p>Thank you,</p>
Clement Wong
<p>Are you using OS or commercial BIRT? What version and build number?</p>
<p> </p>
<p>Commercial BIRT already includes jQuery. You can call jQuery from the clientScripts > onRender (commercial only), or from a Text Report Item in a <SCRIPT>.</p>
<p> </p>
<p>Attached is a simple example with commercial BIRT. Another extensive example (DevShare) with commercial BIRT @ <a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/files/file/1106-birt-with-the-power-of-jquery/'>http://developer.actuate.com/community/forum/index.php?/files/file/1106-birt-with-the-power-of-jquery/</a>
. </p>
<p> </p>
mahbodtaba
<p>Hi I have question...I add datecalender.js into resource in property editor , but how can I or better than say where can I write javascript code in birt report???</p>
Clement Wong
<p>I'm not sure I quite the context of your question. If you're asking if you can use JavaScript for client side scripting in your report, then yes, you can just use a Text Report Item, and then change the format drop down from "Auto" to "HTML". Then you can write <SCRIPT>...</SCRIPT> in that control.</p>
<p> </p>
<p>There's also the <em>clientScripts > clientInitialize</em> event (<a href="
; And in commercial BIRT, there is the addition of the <em>clientScripts > onRender </em>event.</p>