-
I have an XPage that uses facets. The top level callback set is used to create a template that’s used for each page on the web site, with the facet tag defining what goes in the content. I’m attempting to add a JS library import in beforePageLoad on that template so every page on the web site will have access to the functions in that library.
-
However, when I add:
xp:this.beforePageLoad<![CDATA[${javascript:
import <jslibrary name>;
}]]></xp:this.beforePageLoad>
to the template custom control, I get the error in the subject line: “Invalid method binding expression, cannot be null”. I also get a stack trace, but it only references existing and constructed Java objects, not anything in the XPage itself, so I have no way to resolve why this error is actually occurring, other than the attempt to import the library does it.
- Is there a way to include a library like this, or do I have to include it in every single custom control it’s used in?
Thanks for your time…
Subject: SOLVED: This is uncanny…
-
I’ve looked for nearly two hours to find a solution, and literally seconds after posting the question … bam … found the solution. It’s near-miraculous how I can search for any length of time for something, then as soon as I post to the forum I find the answer.
-
The answer, in case this should help someone else, is to use something from the the library. It doesn’t matter what, and if the library includes another library it doesn’t matter what is used from any library, as long as something is used.
-
For example, let’s say one of the imported libraries has a getJSValue() function that fetches the value of a JS global variable. Then add a line after the import to get the value of any JS global variable, and XPages will be happy:
xp:this.beforePageLoad<![CDATA[${javascript:
import jsLibrary;
var tossIt=getJSValue(anyJSvariable);
}]]></xp:this.beforePageLoad>
-
It doesn’t matter one whit what function you call or if you even use the value, one simply must call something somewhere, so the XPage doesn’t think there is a “null binding”. If that critical function call isn’t included, and only the import line appears, it will fail every single time.
-
This does in fact make “jsLibrary” and all its objects and functions available globally when placed on a facet/callback page template.
-
Hope this helps…