1

我需要从类似于this issue的java bean调用ssjs 。问题是我需要执行的代码来自配置文档,可能看起来像:

getComponent("xxx").getValue();

我已经建立了一个版本:

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();

但我明白了"Exception in xxx: com.ibm.xsp.exception.EvaluationExceptionEx: Error while executing JavaScript computed expression"

我想我已经很近了,但我看不到山那边..有什么想法吗?

4

1 回答 1

2

有几种可能性:

  1. 变量计算为空

  2. 计算包含非法字符

  3. 计算中的代码格式错误/没有正确的语法

  4. SSJS 代码中不返回任何对象:

    如果您的 SSJS 代码未返回任何内容,则 vb.getValue(fc)将返回nulltoString()将失败。为了防止这种情况,您应该明确地转换您的返回对象:

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

希望这可以帮助

斯文

编辑
重新阅读您的帖子后,我看到您想在动态 SSJS 代码中执行getComponent。这不适用于添加到javax.faces.application.Application的值绑定。为此,您必须改用com.ibm.xsp.page.compiled.ExpressionEvaluatorImpl对象:

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);
于 2012-04-26T06:16:15.423 回答