{"id":2080,"date":"2015-07-02T08:56:41","date_gmt":"2015-07-02T06:56:41","guid":{"rendered":"http:\/\/hasselba.ch\/blog\/?p=2080"},"modified":"2015-07-02T13:21:26","modified_gmt":"2015-07-02T11:21:26","slug":"xpages-bindings-ssjs-el-and-bindings","status":"publish","type":"post","link":"https:\/\/hasselba.ch\/blog\/?p=2080","title":{"rendered":"XPages: SSJS, EL and Bindings"},"content":{"rendered":"<p><a href=\"https:\/\/hasselba.ch\/blog\/?p=1371\">Because of reasons you should already know<\/a>\u00a0I 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 &#8211; this will not work when using a binding.<\/p>\n<p>Let&#8217;s look for example at a repeat control which is bound to the variable\u00a0<em>repeat.<\/em>\u00a0It can be easily accessed everywhere in SSJS, EL or Java, and\u00a0it is much faster than searching the component in the tree. Here it is accessed in a label:<\/p>\n<pre><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;xp:view xmlns:xp=\"http:\/\/www.ibm.com\/xsp\/core\"&gt;\r\n\r\n\u00a0\u00a0 \u00a0&lt;xp:label\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0value=\"#{repeat.rowCount}\"\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0id=\"labelCount\"&gt;\r\n\u00a0\u00a0 \u00a0&lt;\/xp:label&gt;\r\n\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0&lt;xp:repeat\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0id=\"repeatDemo\"\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0rows=\"30\"\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0binding=\"#{repeat}\"&gt;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;xp:this.value&gt;&lt;![CDATA[#{javascript:[1,2,3,4,5]}]]&gt;&lt;\/xp:this.value&gt;\r\n\u00a0\u00a0 \u00a0&lt;\/xp:repeat&gt;\r\n\u00a0\u00a0 \u00a0\r\n&lt;\/xp:view&gt;<\/code><\/pre>\n<p>But this will lead into an error, because the <em>XspDataIterator<\/em> component has only a getter method for the <em>rowCount<\/em> property, not a corresponding setter.<\/p>\n<p><a href=\"https:\/\/hasselba.ch\/blog\/wp-content\/uploads\/2015\/07\/2015-07-01-23_11_16-Runtime-Error.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2081 size-large\" src=\"https:\/\/hasselba.ch\/blog\/wp-content\/uploads\/2015\/07\/2015-07-01-23_11_16-Runtime-Error-1024x427.png\" alt=\"2015-07-01 23_11_16-Runtime Error\" width=\"640\" height=\"267\" srcset=\"https:\/\/hasselba.ch\/blog\/wp-content\/uploads\/2015\/07\/2015-07-01-23_11_16-Runtime-Error-1024x427.png 1024w, https:\/\/hasselba.ch\/blog\/wp-content\/uploads\/2015\/07\/2015-07-01-23_11_16-Runtime-Error-300x125.png 300w, https:\/\/hasselba.ch\/blog\/wp-content\/uploads\/2015\/07\/2015-07-01-23_11_16-Runtime-Error.png 1422w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>When changing the code to a SSJS method call,\u00a0it\u00a0works without any problems:<\/p>\n<pre><code>\u00a0\u00a0\u00a0 &lt;xp:label\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0value=\"#{javascript:repeat.getRowCount()}\"\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0id=\"labelCount\"&gt;\r\n\u00a0\u00a0 \u00a0&lt;\/xp:label&gt;<\/code><\/pre>\n<p>The reason for this behaviour can be found deep down in the underlying JSF classes: The <em>BeanInfoManager<\/em>\u00a0ignores all methods without a &#8222;valid&#8220; getter\/setter methods pair during the inspection of a class, and doesn&#8217;t add it to the available properties for the PropertyResover. The <em>rows<\/em> property for example has a pair of those methods, that&#8217;s why this works without any problem:<\/p>\n<pre><code>&lt;xp:label\r\n    value=\"#{repeat.rows}\"\r\n    id=\"labelCount\"&gt;\r\n&lt;\/xp:label&gt;<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Because of reasons you should already know\u00a0I 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 &hellip; <a href=\"https:\/\/hasselba.ch\/blog\/?p=2080\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,26,74],"tags":[47,7,86,3],"class_list":["post-2080","post","type-post","status-publish","format-standard","hentry","category-allgemein","category-jsf","category-xpages","tag-9-0","tag-domino","tag-jsf","tag-xpages"],"_links":{"self":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2080","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2080"}],"version-history":[{"count":6,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2080\/revisions"}],"predecessor-version":[{"id":2091,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2080\/revisions\/2091"}],"wp:attachment":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}