I have an unwritten rule that if I learn something and I think I’ll hit the same problem again, I try to blog about it; if I hit it again and I can’t find it on my blog, I definitely blog about it.

Yesterday I encountered the latter, so today I’m blogging about it.

As I’ve moved through understanding the languages in XPages, I use Expression Language more and more. But consider the following example:

<xp:button value="Label" id="button1">
<xp:eventHandler event="onclick" submit="false">
<xp:this.script><![CDATA[alert('#{database.filePath()}');]]></xp:this.script>
</xp:eventHandler>
</xp:button>

It seems a more efficient manner of adding an alert with the current database file path – shorter to type and better performant. Except it throws an error when it hits the browser. The stack trace is as follows, triggering the error from the createView method which runs before the XPages beforePageLoad event:

javax.faces.el.ReferenceSyntaxException: alert('#{database.filePath}');
    com.sun.faces.el.MethodBindingImpl.<init>(MethodBindingImpl.java:73)
    com.sun.faces.application.ApplicationImpl.createMethodBinding(ApplicationImpl.java:277)
    com.ibm.xsp.application.ApplicationExImpl.createMethodBinding(ApplicationExImpl.java:1117)
    com.ibm.xsp.page.compiled.ExpressionEvaluatorImpl.createMethodBinding(ExpressionEvaluatorImpl.java:87)
    xsp.CSJS_005fEL$CSJS_005fELPage.createEventHandler(CSJS_005fEL.java:135)

Add SSJS as well:

<xp:button value="This errors" id="button3">
<xp:eventHandler event="onclick" submit="false">
<xp:this.script><![CDATA[alert('#{database.filePath} and #{javascript:database.getFilePath()}');]]></xp:this.script>
</xp:eventHandler>
</xp:button>

and you get a different stack trace and error, as its being processed during the Render Response phase:

javax.faces.el.MethodNotFoundException: filePath: com.ibm.domino.xsp.module.nsf.NSFComponentModule$XPagesDatabase.filePath()
    com.sun.faces.el.MethodBindingImpl.method(MethodBindingImpl.java:207)
    com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:136)
    com.ibm.xsp.binding.MultiPartMethodBinding.invoke(MultiPartMethodBinding.java:87)
    com.ibm.xsp.renderkit.html_extended.EventHandlerRenderer.processHandlers(EventHandlerRenderer.java:124)

It seems you can’t use Expression Language in a CSJS eventHandler. It’s fine in an Output Script control or the onComplete of an eventHandler, but not in the script property of an eventHandler.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.