Parameters in EL Methods

I want to use a method in JSP using EL, which has a parameter. But EL does not support parameters in methods. Actually, I want to show a table in which there is a field that displays a list of values ​​in one cell. For each cell, this list will be different, it depends on the parameter. How to do this using EL?

I tried this, but says that it cannot use Integer for String in <c:set var="group" value="${entrant.idGroup}" /> where entrant.idGroup returns int

  <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?

0
source share
1 answer

Support for passing method arguments and calling methods other than getters was introduced in EL 2.2, which is part of Servlet 3.0. Therefore, it’s best to switch to a Servlet 3.0 compatible container like Tomcat 7, Glassfish 3, JBoss AS 6 and make sure your web.xml declared as compliant with the Servlet 3.0 specification, so 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 does not support it, it is best to create a custom EL function.

  <td>${some:getGroupCode(bean, entrant.idGroup)}</td> 
+6
source

Source: https://habr.com/ru/post/1380501/


All Articles