Skip to main content



      Home
Home » Archived » BIRT » Getting a class instance from javascript.
Getting a class instance from javascript. [message #77865] Thu, 29 September 2005 09:47 Go to next message
Eclipse UserFriend
Originally posted by: coqueln.yahoo.fr

Hi,

I try to use a POJO as a Scripted Data Source.

In my class RunReport, I put an object in the config
: config.addScriptableJavaObject("myObj", new myClass());

But how can I get this objet in the Open method of the scripted data set?
I notice that I can instantiate a new objet :
obj = new Packages.com.company.myClass();
But this is a new instance and not the object that I put in the config.
Re: Getting a class instance from javascript. [message #77881 is a reply to message #77865] Thu, 29 September 2005 10:25 Go to previous messageGo to next message
Eclipse UserFriend
Nicolas,

Lets say that myClass has a method to return an int, you should be able in
the script editor say
var test = myObj.myIntMethod();
The first parameter is how you reference in script.
Keep in mind that you are creating a new instance in the config line below.
It might be better to do something like
myClass mc = new myClass();
//set some properties
//then
config.addScriptableJavaObject("myObj", mc);

Jason Weathersby
BIRT PMC



"Nicolas Coquel" <coqueln@yahoo.fr> wrote in message
news:aed866dccb55e41a4708524a6defab38$1@www.eclipse.org...
> Hi,
>
> I try to use a POJO as a Scripted Data Source.
>
> In my class RunReport, I put an object in the config :
> config.addScriptableJavaObject("myObj", new myClass());
>
> But how can I get this objet in the Open method of the scripted data set?
> I notice that I can instantiate a new objet :
> obj = new Packages.com.company.myClass();
> But this is a new instance and not the object that I put in the config.
>
>
Re: Getting a class instance from javascript. [message #77944 is a reply to message #77881] Thu, 29 September 2005 11:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: coqueln.yahoo.fr

Ok,

Now, I have two others problems :

1.
When I declare a variable in the "open" method, it's not seen in the
"fetch" method.

open:
var test = myObj.myIntMethod();

fetch:
row["column1"] = test;
return true;

Java error :
29 sept. 2005 16:58:01
org.eclipse.birt.report.engine.data.dte.DteDataEngine execute
GRAVE: Expression Javascript incorrecte. Source : DataSet:scriptJDD.fetch,
ligne :0, expression :
function_prefix_1128005881032();function
function_prefix_1128005881032(){row["column1"] = test;
return true;}
Script Engine Error : ReferenceError: "test" is not defined




2.
When I call a method of my object in the "fetch" method, I have a
"java.lang.OutOfMemoryError"

Open :


fetch:
row["column1"] = myObj.myIntMethod();
return true;

Java error :
29 sept. 2005 17:07:43
org.eclipse.birt.report.engine.executor.DataItemExecutor execute
GRAVE: Error:
java.lang.OutOfMemoryError
29 sept. 2005 17:08:05
org.eclipse.birt.report.engine.executor.DataItemExecutor execute
GRAVE: Error:
java.lang.OutOfMemoryError
29 sept. 2005 17:08:28
org.eclipse.birt.report.engine.executor.DataItemExecutor execute
GRAVE: Error:
java.lang.OutOfMemoryError


Thanks,
Nicolas
Re: Getting a class instance from javascript. [message #77973 is a reply to message #77944] Thu, 29 September 2005 13:42 Go to previous messageGo to next message
Eclipse UserFriend
Try removing the var, i.e.
test = myObj.myIntMethod();
instead of
var test = myObj.myIntMethod();
/Petter Ivmark
"Nicolas Coquel" <coqueln@yahoo.fr> wrote in message
news:05204ee788b580ebd14eb7bd7f80942b$1@www.eclipse.org...
> Ok,
>
> Now, I have two others problems :
>
> 1.
> When I declare a variable in the "open" method, it's not seen in the
> "fetch" method.
>
> open:
> var test = myObj.myIntMethod();
>
> fetch:
> row["column1"] = test;
> return true;
>
> Java error :
> 29 sept. 2005 16:58:01
> org.eclipse.birt.report.engine.data.dte.DteDataEngine execute
> GRAVE: Expression Javascript incorrecte. Source : DataSet:scriptJDD.fetch,
> ligne :0, expression :
> function_prefix_1128005881032();function
> function_prefix_1128005881032(){row["column1"] = test;
> return true;}
> Script Engine Error : ReferenceError: "test" is not defined
>
>
>
>
> 2.
> When I call a method of my object in the "fetch" method, I have a
> "java.lang.OutOfMemoryError"
>
> Open :
>
>
> fetch:
> row["column1"] = myObj.myIntMethod();
> return true;
>
> Java error :
> 29 sept. 2005 17:07:43
> org.eclipse.birt.report.engine.executor.DataItemExecutor execute
> GRAVE: Error:
> java.lang.OutOfMemoryError
> 29 sept. 2005 17:08:05
> org.eclipse.birt.report.engine.executor.DataItemExecutor execute
> GRAVE: Error:
> java.lang.OutOfMemoryError
> 29 sept. 2005 17:08:28
> org.eclipse.birt.report.engine.executor.DataItemExecutor execute
> GRAVE: Error:
> java.lang.OutOfMemoryError
>
>
> Thanks,
> Nicolas
>
>
Re: Getting a class instance from javascript. [message #78105 is a reply to message #77973] Fri, 30 September 2005 09:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: coqueln.yahoo.fr

With
test = myObj.myIntMethod()
instead of
var test = myObj.myIntMethod();
it's works better.

But I still have a "java.lang.OutOfMemoryError" when call a method of my
object (from the "open" or "fetch" method of the Scripted Data Set).

Maybe the engine is not able to find the class?

I put the class with the package structure in this directory :
[eclipse]\plugins\org.eclipse.birt.report.viewer_1.0.1\birt\ WEB-INF\classes
I put a jar of my application in this directory :
[eclipse]\plugins\org.eclipse.birt.report.viewer_1.0.1\birt\ WEB-INF\lib

I also try to use the Birt Report Engine instead of the Eclipse plugin :
config.setEngineHome("C:\\[directory]\\Birt\\birt-runtime-1_0_1\\Report
Engine");
instead of
config.setEngineHome(" C:\\eclipse\\plugins\\org.eclipse.birt.report.viewer_1.0.1\\ birt ");
But in this case, where should I put my class?

I use the following configuration :
J2sdk 1.4.2
Eclipse 3.1.0 (I also try with eclipse 3.0.1)
Birt 1_0_1
GEF 3.1
EMF 2.1

Thanks,
Nicolas
Re: Getting a class instance from javascript. [message #78200 is a reply to message #78105] Fri, 30 September 2005 13:25 Go to previous message
Eclipse UserFriend
I'm pretty sure the class is found. You are probably getting an
OutOfMemoryError because the fetch method keeps looping, you always return
true. You need a break condition in the fetch method and return false.
Example:
In the open method:
count = 0;

In the fetch method:
if (count < 10) {
count++;
//do stuff here
return true;
}
return false;

Hope this helps.

Petter Ivmark

"Nicolas Coquel" <coqueln@yahoo.fr> wrote in message
news:dd2985ea512c8344e1c9ae9d1fa48d17$1@www.eclipse.org...
> With test = myObj.myIntMethod() instead of
> var test = myObj.myIntMethod();
> it's works better.
>
> But I still have a "java.lang.OutOfMemoryError" when call a method of my
> object (from the "open" or "fetch" method of the Scripted Data Set).
>
> Maybe the engine is not able to find the class?
>
> I put the class with the package structure in this directory :
> [eclipse]\plugins\org.eclipse.birt.report.viewer_1.0.1\birt\ WEB-INF\classes
> I put a jar of my application in this directory :
> [eclipse]\plugins\org.eclipse.birt.report.viewer_1.0.1\birt\ WEB-INF\lib
>
> I also try to use the Birt Report Engine instead of the Eclipse plugin :
> config.setEngineHome("C:\\[directory]\\Birt\\birt-runtime-1_0_1\\Report
> Engine");
> instead of
> config.setEngineHome(" C:\\eclipse\\plugins\\org.eclipse.birt.report.viewer_1.0.1\\ birt ");
> But in this case, where should I put my class?
>
> I use the following configuration : J2sdk 1.4.2
> Eclipse 3.1.0 (I also try with eclipse 3.0.1)
> Birt 1_0_1
> GEF 3.1
> EMF 2.1
>
> Thanks,
> Nicolas
>
>
Previous Topic:dynamic BIRT ?
Next Topic:ROM UserProperty structure
Goto Forum:
  


Current Time: Sat Apr 26 06:09:54 EDT 2025

Powered by FUDForum. Page generated in 0.03432 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top