tags:

views:

68

answers:

1

Invoking methods using EL Expression:

Can I get the size of a list using an EL Expression? e.g.

<h:outputText value="#{myList.size()}" />

This doesnt seem to work.

+2  A: 

In standard EL prior to EL 2.2 from Java EE 6 you cannot pass method arguments like that.

You need to either upgrade to a EL 2.2 / Java EE 6 compliant container, or to install JBoss-EL where you can pass method arguments in EL like that. Put jboss-el.jar in /WEB-INF/lib and add the following to the web.xml, assuming you're using Mojarra:

<context-param>     
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>org.jboss.el.ExpressionFactoryImpl</param-value>   
</context-param>

If you're using JSF on JSP, an alternative is to use JSTL's fn:length.

<h:outputText value="#{fn:length(bean.list)}" />

Another alternative is to add a getter to the bean which returns List#size().

BalusC