{"id":1037,"date":"2010-11-08T12:26:21","date_gmt":"2010-11-08T12:26:21","guid":{"rendered":"http:\/\/salientsoft.co.uk\/?p=1037"},"modified":"2010-11-08T12:44:48","modified_gmt":"2010-11-08T12:44:48","slug":"using-jstl-functions-in-jsf-el-e-g-to-return-list-size","status":"publish","type":"post","link":"https:\/\/salientsoft.co.uk\/?p=1037","title":{"rendered":"Using JSTL Functions in JSF EL e.g. to return list size"},"content":{"rendered":"<p>Unfortunately some methods of backing beans, such as <em>size()<\/em> to return the number of entries in a list in a bean, are not directly callable from an EL expression as they are not exposed as standard getters. Whilst expressions on a facelets page should be used with care so as not to include business logic on the page, they are sometimes useful. One of my use cases has been to optionally add a css class into a <em>stylclass <\/em>attribute to correct the width of a table header when scrollbars are present (when enough rows are present to cause scrolling).<\/p>\n<p>You can add additional properties to the beans to do this, but an easier way is often to use JSTL functions on the page. The following declaration includes the namespace for them, using prefix <em>fn<\/em>:-<\/p>\n<p style=\"padding-left: 30px;\">&lt;!DOCTYPE HTML&gt;<br \/>\n&lt;html xmlns=&#8221;<a href=\"http:\/\/www.w3c.org\/1999\/xhtml&quot;\">http:\/\/www.w3c.org\/1999\/xhtml&#8221;<\/a><br \/>\nxmlns:f=&#8221;<a href=\"http:\/\/java.sun.com\/jsf\/core&quot;\">http:\/\/java.sun.com\/jsf\/core&#8221;<\/a><br \/>\nxmlns:h=&#8221;<a href=\"http:\/\/java.sun.com\/jsf\/html&quot;\">http:\/\/java.sun.com\/jsf\/html&#8221;<\/a><br \/>\n<strong><em>xmlns:fn=&#8221;<\/em><\/strong><a href=\"http:\/\/java.sun.com\/jsp\/jstl\/functions&quot;\"><strong><em>http:\/\/java.sun.com\/jsp\/jstl\/functions&#8221;<\/em><\/strong><\/a><br \/>\nxmlns:p=&#8221;<a href=\"http:\/\/primefaces.prime.com.tr\/ui&quot;\">http:\/\/primefaces.prime.com.tr\/ui&#8221;<\/a>&gt;<\/p>\n<p>\u00a0<\/p>\n<p>The following code fragment calls the <em>length <\/em>function to return the size of a list :-<\/p>\n<p style=\"padding-left: 30px;\">&lt;p:dataTable var=&#8221;car&#8221; value=&#8221;#{tableBean.carsSmall}&#8221; scrollable=&#8221;true&#8221;\u00a0<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 styleClass=&#8221;#{fn:length(tableBean.carsSmall) lt 8 ? &#8221; : &#8216;ss-tableheader-scrolladjust&#8217;}&#8221; height=&#8221;200&#8243; &gt;<\/p>\n<p>\u00a0The javadoc for the complete set of jstl functions may be found <strong><a title=\"http:\/\/download.oracle.com\/javaee\/5\/jstl\/1.1\/docs\/tlddocs\/fn\/tld-summary.html\" href=\"http:\/\/download.oracle.com\/javaee\/5\/jstl\/1.1\/docs\/tlddocs\/fn\/tld-summary.html\">here<\/a>.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unfortunately some methods of backing beans, such as size() to return the number of entries in a list in a bean, are not directly callable from an EL expression as they are not exposed as standard getters. Whilst expressions on a facelets page should be used with care so as not to include business logic [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22],"tags":[76,40,184,16],"_links":{"self":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1037"}],"collection":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1037"}],"version-history":[{"count":4,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1037\/revisions"}],"predecessor-version":[{"id":1039,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1037\/revisions\/1039"}],"wp:attachment":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}