Skip to main content



      Home
Home » Archived » BIRT » Errors when using javascript
Errors when using javascript [message #149791] Fri, 31 March 2006 00:26 Go to next message
Eclipse UserFriend
Originally posted by: pkustack.gmail.com

I am using a scripted set.
This is the "open" script:
metrics = new Packages.mypackage.metrics(); 1)
But what i really want to do is :
metricsclass = java.lang.forName(params["metrics"]);
metrics = metricsclas.newInstance(); 2)

I use Rhino javascript debugger to test the code,both ways are working.
But after i copy the code to birt,the second one fails.
I also test the code:
java.lang.Class.forName("java.lang.Integer");
It works.

Please tell me why this is happening,thank you.
ps:I've copied mypackage.metrics.class to
org.eclipse.birt.report.viewer\birt\WEB-INFO\classes directory.and
params["metrics"] is "mypackage.metrics".
Re: Errors when using javascript [message #149867 is a reply to message #149791] Fri, 31 March 2006 03:07 Go to previous messageGo to next message
Eclipse UserFriend
lihe a écrit :
> I am using a scripted set.
> This is the "open" script:
> metrics = new Packages.mypackage.metrics(); 1)
> But what i really want to do is :
> metricsclass = java.lang.forName(params["metrics"]);
> metrics = metricsclas.newInstance(); 2)
>
> I use Rhino javascript debugger to test the code,both ways are working.
> But after i copy the code to birt,the second one fails.
> I also test the code:
> java.lang.Class.forName("java.lang.Integer");
> It works.
>
> Please tell me why this is happening,thank you.
> ps:I've copied mypackage.metrics.class to
> org.eclipse.birt.report.viewer\birt\WEB-INFO\classes directory.and
> params["metrics"] is "mypackage.metrics".
>
>
you forget "Class" :
metricsclass = java.lang.Class.forName(params["metrics"]);

and if you have error in script, have a look in the html source in the
viewer, you can see at the end the stack trace
Re: Errors when using javascript [message #149939 is a reply to message #149867] Fri, 31 March 2006 06:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pkustack.gmail.com

Hello:
Thank you very much for answering my question.
But that is just a writing mistake,i typed the wrong code.
My actual code is "java.lang.Class.forName("mypackage.metrics")".
I discussed the problem with a colleague this afternoon,I think we've
figured out what the problem is.
But i'm not sure about it.
Here is my explaination:
Javascript is run at client side.But the class mypackage.metrics is at
server side.
So when script is executing,class loader will not find mypackage.metrics.
But new Packages.mypackage.metrics();use a different way to load the class.I
don't know what exactly it is.
My solution is use javascript "eval" function:
eval("new Packages."+params["metrics"]);
Could any one give me a more detailed explaination?
Thank you in advance.
"S
Re: Errors when using javascript [message #150020 is a reply to message #149939] Fri, 31 March 2006 07:56 Go to previous message
Eclipse UserFriend
One way to accomplish a dynamic name is using the JavaScript eval command.
Try this:

testclsname = "new Packages.my.simple.code."+params["clsnm"]+"()";
testobj = eval(testclsname);
testobj.getMyValue();

I put this code in the expression builder for a data control and my
parameter passes in the class name.
Works great.

Jason


"lihe" <pkustack@gmail.com> wrote in message
news:e0j5mn$nrm$1@utils.eclipse.org...
> Hello:
> Thank you very much for answering my question.
> But that is just a writing mistake,i typed the wrong code.
> My actual code is "java.lang.Class.forName("mypackage.metrics")".
> I discussed the problem with a colleague this afternoon,I think we've
> figured out what the problem is.
> But i'm not sure about it.
> Here is my explaination:
> Javascript is run at client side.But the class mypackage.metrics is at
> server side.
> So when script is executing,class loader will not find mypackage.metrics.
> But new Packages.mypackage.metrics();use a different way to load the
> class.I don't know what exactly it is.
> My solution is use javascript "eval" function:
> eval("new Packages."+params["metrics"]);
> Could any one give me a more detailed explaination?
> Thank you in advance.
> "S
Previous Topic:change language
Next Topic:text direction
Goto Forum:
  


Current Time: Wed Jul 23 18:02:50 EDT 2025

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

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

Back to the top