Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First create a <code>final</code> class with a <code>public static</code> method which does exactly the job you want:</p> <pre class="lang-java prettyprint-override"><code>package com.example; import java.util.Collection; public final class Functions { private Functions() { // Hide constructor. } public static boolean contains(Collection&lt;Object&gt; collection, Object item) { return collection.contains(item); } } </code></pre> <p>Then define it as a <code>facelet-taglib</code> in <code>/WEB-INF/functions.taglib.xml</code>:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;facelet-taglib xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd" version="2.0"&gt; &lt;namespace&gt;http://example.com/functions&lt;/namespace&gt; &lt;function&gt; &lt;function-name&gt;contains&lt;/function-name&gt; &lt;function-class&gt;com.example.Functions&lt;/function-class&gt; &lt;function-signature&gt;boolean contains(java.util.Collection, java.lang.Object)&lt;/function-signature&gt; &lt;/function&gt; &lt;/facelet-taglib&gt; </code></pre> <p>Then familarize Facelets with the new taglib in the existing <code>/WEB-INF/web.xml</code>:</p> <pre><code>&lt;context-param&gt; &lt;param-name&gt;javax.faces.FACELETS_LIBRARIES&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/functions.taglib.xml&lt;/param-value&gt; &lt;/context-param&gt; </code></pre> <p><em>(note: if you already have the <code>javax.faces.FACELETS_LIBRARIES</code> definied, then you can just add the new path semicolon separated)</em></p> <p>Then define it in the Facelets XHTML file as new XML namespace:</p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:func="http://example.com/functions" ... &gt; </code></pre> <p>Finally you can use it as intended:</p> <pre><code>rendered="#{func:contains(bean.panels, 'u1')}" </code></pre> <hr> <p>As a completely different alternative, you can also include JBoss EL in your project. It works on Tomcat 6.0 and you'll be able to invoke non-getter methods in EL. Drop <a href="https://maven.atlassian.com/content/repositories/jboss-releases/org/jboss/seam/jboss-el/2.0.0.GA/jboss-el-2.0.0.GA.jar" rel="nofollow noreferrer">jboss-el.jar</a> file in <code>/WEB-INF/lib</code> and add the following to your <code>web.xml</code>:</p> <pre><code>&lt;context-param&gt; &lt;param-name&gt;com.sun.faces.expressionFactory&lt;/param-name&gt; &lt;param-value&gt;org.jboss.el.ExpressionFactoryImpl&lt;/param-value&gt; &lt;/context-param&gt; </code></pre> <hr> <p>Since EL 2.2 there's another approach: create an <code>@ApplicationScoped</code> bean with methods in turn referring to those static functions. See also a.o. <a href="https://stackoverflow.com/questions/36718276/utility-methods-in-application-scoped-bean">Utility methods in application scoped bean</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload