Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Custom server side javascript issue in Birt web viewer(Custom server side javascript issue in Birt web viewer)
Custom server side javascript issue in Birt web viewer [message #906082] Fri, 31 August 2012 11:21 Go to next message
birt user is currently offline birt user
Messages: 11
Registered: August 2012
Junior Member
I have created a javascript for logging. The name of the file is logging.js. Here is the code
========================================
var logFile="F:/logFile.txt";
var loggingEnabled=true;
var printWriter;
function createLogger(method,message)
{
if (loggingEnabled && printWriter == null)
{
importPackage( Packages.java.io );
fos = new java.io.FileOutputStream( logFile, true );
printWriter = new java.io.PrintWriter( fos );
}
if(loggingEnabled && printWriter != null)
{
logMessage(method,message);
}
}
function logMessage(method,message)
{

if (loggingEnabled && printWriter != null)
{
printWriter.println(method + ":" + message);
}
}
function closeLogger(method,message)
{
if (loggingEnabled && printWriter != null)
{
logMessage(method,message);
printWriter.close();
}
}
===================================================
I have added this script under Resources (javascript files) section of the report. When i use these js functions in my report and run it under eclipse or report designer, no problems

But when I copy the script and the report to birt viewer, it gives me error

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Wrapped org.eclipse.birt.core.exception.CoreException: There are errors evaluating script "createLogger":
ReferenceError: "createLogger" is not defined. (<inline>#1) (/report/method[@name="initialize"]#2) (Element ID:1)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

I copied the script under tomcat birt folder and also copied it under webcontent folder. Not sure why it does not work under viewer. Any help would be appreciated

thanks

birt user
Re: Custom server side javascript issue in Birt web viewer [message #906126 is a reply to message #906082] Fri, 31 August 2012 12:57 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Take a look at this post:
http://birtworld.blogspot.com/2012/07/using-global-js-function-across-birt.html

Add the js file to the report and put the js file in the resource folder.


Jason


On 8/31/2012 11:21 AM, birt user wrote:
> I have created a javascript for logging. The name of the file is
> logging.js. Here is the code
> ========================================
> var logFile="F:/logFile.txt";
> var loggingEnabled=true;
> var printWriter;
> function createLogger(method,message)
> {
> if (loggingEnabled && printWriter == null)
> {
> importPackage( Packages.java.io );
> fos = new java.io.FileOutputStream( logFile, true );
> printWriter = new java.io.PrintWriter( fos );
> }
> if(loggingEnabled && printWriter != null)
> {
> logMessage(method,message);
> }
> }
> function logMessage(method,message)
> {
>
> if (loggingEnabled && printWriter != null)
> {
> printWriter.println(method + ":" + message);
> }
> }
> function closeLogger(method,message)
> {
> if (loggingEnabled && printWriter != null)
> {
> logMessage(method,message);
> printWriter.close();
> }
> }
> ===================================================
> I have added this script under Resources (javascript files) section of
> the report. When i use these js functions in my report and run it under
> eclipse or report designer, no problems
>
> But when I copy the script and the report to birt viewer, it gives me error
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> Wrapped org.eclipse.birt.core.exception.CoreException: There are errors
> evaluating script "createLogger":
> ReferenceError: "createLogger" is not defined. (<inline>#1)
> (/report/method[@name="initialize"]#2) (Element ID:1)
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> I copied the script under tomcat birt folder and also copied it under
> webcontent folder. Not sure why it does not work under viewer. Any help
> would be appreciated
>
> thanks
>
> birt user


Jason Weathersby

BIRT Exchange
Re: Custom server side javascript issue in Birt web viewer [message #911010 is a reply to message #906126] Mon, 10 September 2012 16:03 Go to previous messageGo to next message
birt user is currently offline birt user
Messages: 11
Registered: August 2012
Junior Member
Hello Jason,

in Birt viewer web.xml the resource folder is configured like this
<!-- Resource location directory. Defaults to ${birt home} -->
<context-param>
<param-name>BIRT_RESOURCE_PATH</param-name>
<param-value></param-value>
</context-param>

Which basically is the default. I placed the script in this location which is
....../webapps/birt. This is where I have also placed my reports. I have also added the reference to the external js in my report, but problem still persists

any help

birt user
Re: Custom server side javascript issue in Birt web viewer [message #911403 is a reply to message #911010] Tue, 11 September 2012 10:29 Go to previous message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Can you post the report? Did you set a resource folder in your designer. I am wondering if the full path to the js file is in the report. It should not be. Try creating a resource folder in your project, something like resources and set this as the resource folder in your designer preferences. See the blog reference I posted earlier to see how to do this. Put the js file in the resource folder and add it to the report. Next create a folder in the webviewer named something like resources, and put the js file in this folder. Set the BIRT_RESOURCE_PATH to the value resources and try the deployed report.

Jason


Jason Weathersby

BIRT Exchange
Previous Topic:use BIRT within app jEE
Next Topic:how to render charts to stream or object (png, svg)
Goto Forum:
  


Current Time: Fri Apr 18 22:02:54 EDT 2014

Powered by FUDForum. Page generated in 0.02520 seconds