0

I want to use a method in JSP using EL that has a parameter. But EL doesn't support parameters in methods. Actually I want to show a table, which has a field that output a list of values in one cell. For every cell this list will be different, it depends on parameter. How can I do this using EL?

I have tried this, but is says that it can not cast Integer to String in <c:set var="group" value="${entrant.idGroup}" /> where entrant.idGroup return int value

    <c:forEach var="entrant" items="${bean.entrants}">
                <tr>
            <td>${entrant.idEntrant}</td>
                    <c:set var="group" value="${entrant.idGroup}" />
                    <td><%=bean.getGroupCode(Integer.parseInt((String)pageContext.getAttribute("group")))%></td>
            <td>${entrant.name}</td>
     </c:forEach>

But even if it works, I want to use pure EL in JSP. How can I achieve this?

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
maks
  • 5,911
  • 17
  • 79
  • 123
  • Please don't confuse JSTL with EL. Throughout your question you was talking about EL as if it was JSTL. I've swept the one and other. Please read our wiki pages to learn about the difference: http://stackoverflow.com/tags/jstl/info and http://stackoverflow.com/tags/el/info – BalusC Jun 13 '11 at 22:38

1 Answers1

6

The support for passing method arguments and invoking non-getter methods was introduced in EL 2.2 which is part of Servlet 3.0. So your best bet is to upgrade to a Servlet 3.0 compatible container, such as Tomcat 7, Glassfish 3, JBoss AS 6 and ensure that your web.xml is declared conform Servlet 3.0 spec, so that you can do the following:

<c:forEach var="entrant" items="${bean.entrants}">
    <tr>
        <td>${entrant.idEntrant}</td>
        <td>${bean.getGroupCode(entrant.idGroup)}</td>
        <td>${entrant.name}</td>
    </tr>
</c:forEach>

If your container doesn't support it, then your best bet is to create a custom EL function.

        <td>${some:getGroupCode(bean, entrant.idGroup)}</td>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555