1

I need to call ssjs from a java bean similar to this this issue. The issue is that the code I need to execute comes from a configuration document, and may look like:

getComponent("xxx").getValue();

I have built a version that does :

String compute = doc.getItemValueString("SSJSStuff");
String valueExpr = "#{javascript:" + compute + "}";
FacesContext fc = FacesContext.getCurrentInstance();
Application app = fc.getApplication();
ValueBinding vb = app.createValueBinding(valueExpr);
String vreslt = vb.getValue(fc).toString();

but I get "Exception in xxx: com.ibm.xsp.exception.EvaluationExceptionEx: Error while executing JavaScript computed expression"

I think I am close, but I do not see over the hill.. Any thoughts?

Community
  • 1
  • 1
Newbs
  • 1,632
  • 11
  • 16

1 Answers1

2

There are several possibilities for this:

  1. The variable compute is empty

  2. compute contains illegal chars

  3. The code inside compute is malformed / has no correct syntax

  4. No object is returned in your SSJS code:

    If your SSJS code does not return something, vb.getValue(fc) returns null. A toString() will fail. To prevent this, you should cast your returning object explicitly:

    vreslt = (String) vb.getValue(fc);
    

Hope this helps

Sven

EDIT:
After re-reading your post, I saw that you want to do a getComponent in your dynamic SSJS Code. This won't work with a value binding added to the javax.faces.application.Application. For this, you have to use the com.ibm.xsp.page.compiled.ExpressionEvaluatorImpl object instead:

String valueExpr = "#{javascript:" + compute + "}";
FacesContext fc = FacesContext.getCurrentInstance();
ExpressionEvaluatorImpl evaluator = new ExpressionEvaluatorImpl( fc );
ValueBinding vb = evaluator.createValueBinding( fc.getViewRoot(), valueExpr, null, null);
vreslt = (String) vb.getValue(fc);
Community
  • 1
  • 1
Sven Hasselbach
  • 10,455
  • 1
  • 18
  • 26
  • The answer is #4 - No object was being returned because the component was not available at that point in the XSP life cycle. I worked around that by passing the NotesDocument from the dataSource into the Java Bean method so I could go against the actual Notes Fields. I am going to look more into that ExpressionEvaluatorImpl though as it has promise for other parts of this project. /Newbs – Newbs Apr 26 '12 at 15:57
  • Is there a way to inject an object to SSJS evaluation like `put(key, object)` in javax.script.ScriptEngine? I would like to evaluate the same script against all documents in Java document collection. – Panu Haaramo Sep 02 '13 at 15:02
  • I ended up using javax.script.ScriptEngine and adding my Domino objects there which works fine. I'm evaluating an SSJS string which has "doc.getItemValue(..". I need to add the "doc" Object from Java to be included in the evaluation. – Panu Haaramo Sep 07 '13 at 09:08