Sep 17, 2012 10:25 AM
135 Posts
topic has been resolvedResolved

Calling Java from SSJS eval() does not work

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 8.5.2
  • Role: Developer
  • Tags: SSJS,Java
  • Replies: 4
Hi,
 
has anyone been able to use SSJS eval() to call a Java class in WEB-INF? For me it just ignores the call, no error no nothing.
 
- Panu 
Sep 17, 2012 10:54 AM
366 Posts
Re: Calling Java from SSJS eval() does not work
 need more information.
 
Why are you using eval? 
 
How are you calling it? 
 
What are you trying to accomplish? 
 
Are you calling a managed bean?  if so what scope? 
Sep 17, 2012 1:24 PM
135 Posts
Re: Calling Java from SSJS eval() does not work
Hi Paul,
 
I've enjoyed your sessions/classes at least in Geneva and Boston!
 
1. Why are you using eval?
 
I have a generic XPage which runs URL param passed SSJS. I use this with an ajax call when I want to run SSJS from outside of XPages, for example from forms. I know this could be a huge security risk but I'm blocking sessionAsSigner and the application runs in intranet only with tight ACL..
 
2. How are you calling it? 
 
eval(param.get("ssjs")); where ssjs URL param is new com.company.Request("therequestid").remove();
 
3. What are you trying to accomplish? 
 
Delete a request in a standard way for which I have a Java method. Of course I can accomplish this without eval but I think the Java call should work also with eval.

4. Are you calling a managed bean? if so what scope?
 
No and that's a good idea. Maybe it would work as a managed bean. I've never used managed beans and am not sure if my Java class would qualify as one.
 
- Panu 
 
 
Sep 17, 2012 8:40 PM
366 Posts
Re: Calling Java from SSJS eval() does not work
 OK, but you don't need eval to call java code
 
 
use the following 
 
 

importPackage(com.mycompany.mycode);

var jc:ClassName = new ClassName();

var retval = jc.getMethod(OptionalParameter);

getComponent("computedField1").setValue(retval); 
Sep 18, 2012 3:38 AM
135 Posts
Re: Calling Java from SSJS eval() does not work
Correct and this thread is about calling Java from eval(). I now got my original (posted above) Java call to work from eval when I hard coded it! There seems to be some encoding/decoding problem with the URL parameter which is causing the problem (althought when printed to log.nsf it looks fine).
 
EDIT: Now everything is solved. I noticed that param.get returns java.lang.Object, not String as I expected. Using eval('' + param.get('ssjs')) solved this. I wonder what other data types than String can we get with param.get?