Because of reasons you should already know I avoid the use of SSJS in my XPages applications, but there are still some parts which can be easy realized in SSJS, but with EL only with a lot of effort. One of this things is accessing properties of a component which has only a getter or a setter – this will not work when using a binding.
Let’s look for example at a repeat control which is bound to the variable repeat. It can be easily accessed everywhere in SSJS, EL or Java, and it is much faster than searching the component in the tree. Here it is accessed in a label:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:label
value="#{repeat.rowCount}"
id="labelCount">
</xp:label>
<xp:repeat
id="repeatDemo"
rows="30"
binding="#{repeat}">
<xp:this.value><![CDATA[#{javascript:[1,2,3,4,5]}]]></xp:this.value>
</xp:repeat>
</xp:view>
But this will lead into an error, because the XspDataIterator component has only a getter method for the rowCount property, not a corresponding setter.
When changing the code to a SSJS method call, it works without any problems:
<xp:label
value="#{javascript:repeat.getRowCount()}"
id="labelCount">
</xp:label>
The reason for this behaviour can be found deep down in the underlying JSF classes: The BeanInfoManager ignores all methods without a „valid“ getter/setter methods pair during the inspection of a class, and doesn’t add it to the available properties for the PropertyResover. The rows property for example has a pair of those methods, that’s why this works without any problem:
<xp:label
value="#{repeat.rows}"
id="labelCount">
</xp:label>