D.Bugger
D.Bugger

Reputation: 2359

XPages: is it possible to call an SSJS function from Java?

I'd like to pass a function parameter (i.e. a FunctionObject) in SSJS to a bean, and then call that function as a kind of callback function. For instance:

companyBox.setGenerator(function() {
    return @DbColumn("", SystemBean.getViewName(), 2);              
});

so that I can call that function whenever I need actualized values.

I'm expecting this to fail because the SSJS-context is missing, but the idea is still tempting. Or maybe it's because the function cannot be Serialized, but what that exactly means I don't know (yet). In this case, the companyBox object is created from a managed bean with view/page scope: once the current page disappears I no longer need it.

Clues are welcome...

Upvotes: 1

Views: 476

Answers (1)

Frantisek Kossuth
Frantisek Kossuth

Reputation: 3524

Yes it is. You have two options.

1) Use "value binding". Thomas Adrian commented about this question, Sven Hasselbach blogged about calling external SSJS library (cool stuff, by the way).

In short: make a call to inner JSF engine to resolve value binding - what can be SSJS (including call to your method) or any other binding (EL). And it works with "on fly" constructed expressions, passed as String.

2) Use Function object as parameter. Blueprint for that technique is available here. Your comment reveals you are aware of com.ibm.jscript package. Well, current implementation of call() method of com.ibm.jscript.std.FunctionObject class will support your empirical observation:

/*     */   public FBSObject call(FBSValueVector paramFBSValueVector) {
/* 163 */     return null;
/*     */   }

Hint: JD Eclipse and JD Eclipse-realign strongly recommended!

The other call method with more complex signature is the way to go. It is used to define custom @Functions, for example this snippet.

Upvotes: 1

Related Questions