EL proposals / autocomplete / code assist in Facelets with Eclipse

Eclipse doesn’t support this out the box. Even the support in JSP is very limited. Only the properties of <jsp:useBean> and managed beans hardcoded as <managed-bean> in faces-config.xml are available by autocomplete. There are however plugins which supports EL autocomplete on @ManagedBean and @Named beans. For example, the JBoss Tools plugin (specifically the CDI feature) … Read more

How to access objects in EL expression language ${}

The expression ${foo} uses behind the scenes JspContext#findAttribute() which searches for attributes in PageContext, HttpServletRequest, HttpSession and ServletContext in this order by their getAttribute(“foo”) method whereby foo from ${foo} thus represents the attribute name “foo” and returns the first non-null object. So, if you do in a servlet ArrayList<Person> persons = getItSomehow(); request.setAttribute(“persons”, persons); // … Read more

EL access a map value by Integer key

Initial answer (EL 2.1, May 2009) As mentioned in this java forum thread: Basically autoboxing puts an Integer object into the Map. ie: map.put(new Integer(0), “myValue”) EL (Expressions Languages) evaluates 0 as a Long and thus goes looking for a Long as the key in the map. ie it evaluates: map.get(new Long(0)) As a Long … Read more

EL expressions not evaluated in JSP

Yes, i have doctype in web.xml <!DOCTYPE web-app PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN” “java.sun.com/dtd/web-app_2_3.dtd”; > Remove that <!DOCTYPE> from web.xml and make sure that the <web-app> is declared conform Servlet 2.4 or newer and all should be well. A valid Servlet 3.0 (Tomcat 7, JBoss AS 6-7, GlassFish 3, etc) compatible web.xml look … Read more

Evaluate empty or null JSTL c tags

How can I validate if a String is null or empty using the c tags of JSTL? You can use the empty keyword in a <c:if> for this: <c:if test=”${empty var1}”> var1 is empty or null. </c:if> <c:if test=”${not empty var1}”> var1 is NOT empty or null. </c:if> Or the <c:choose>: <c:choose> <c:when test=”${empty var1}”> … Read more

How to call a static method in JSP/EL?

You cannot invoke static methods directly in EL. EL will only invoke instance methods. As to your failing scriptlet attempt, you cannot mix scriptlets and EL. Use the one or the other. Since scriptlets are discouraged over a decade, you should stick to an EL-only solution. You have basically 2 options (assuming both balance and … Read more

How to create a custom EL function to invoke a static method?

First create a final class with a public static method which does exactly the job you want: package com.example; import java.util.Collection; public final class Functions { private Functions() { // Hide constructor. } public static boolean contains(Collection<Object> collection, Object item) { return collection.contains(item); } } Then define it as a facelet-taglib in /WEB-INF/functions.taglib.xml: <?xml version=”1.0″ … Read more