Search code examples
jsfforeachjstlexpressionel

c:foreach with EL end value NumberFormatException


I want to use a jstl foreach loop to to display a certain number of elements defined by an attribute of my managed bean:

 <c:forEach begin="0" end="#{MyBean.IntegerProperty}" step="1" var="o" >
   <h:commandButton value="#{MyBean.IntegerProperty}"></h:commandButton>
 </c:forEach>

my taglib declaration is:

 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

however i get this exception:

...
Caused by: java.lang.NumberFormatException: For input string: "#{MyBean.IntegerProperty}"
...

i've read somewhere that foreach and EL do not cooperate too well with each other, if so then does someone know a workaround solution to put that int value in the end attribute of c:foreach?

thank you in advance!


Solution

  • I don't expect what you've got above to work because the JSTL tags don't form part of the Component tree.

    For more, see here