0

I struggle against this bug since days. I tried every methods i've found on internet but it seems that i'm the only one to have this problem.

I've got java classes like this :

Class ListItem{
  private int id;
}

Class ListContainer{
private List<ListItem> items;
}

And a jsp like this :

<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
...
<form:form method="post" action="myController" modelAttribute="listContainerModel">
         <c:forEach items="${listContainerModel.items}" var="currentItem" varStatus="i">
              <form:input type="text" path="items[${i.index}].id" name="id"/>
         </c:forEach>

   </form:form>

But i've got this exception

org.springframework.beans.InvalidPropertyException: Invalid property 'items[${i.index}]' of bean class [foo.bar.ListContainer]: 
Invalid index in property path 'items[${i.index}]'; nested exception is java.lang.NumberFormatException: For input string: "${i.index}"

I've tried many things such as

How to send list of Objects to View and back to Post method in controller post-method-in-controller

or http://viralpatel.net/blogs/spring-mvc-multi-row-submit-java-list/

I suppose i've a problem mixing jstl tags + el expression + spring mvc taglibs but i can't figure out why.

Community
  • 1
  • 1

1 Answers1

0

I finally figure out why.

My web.xml was generated by a template which uses vers 2.3 of servlet. In this version EL expression are ignore by default in JSP. I simply change this :

<!DOCTYPE web-app PUBLIC
  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd" >

to that

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4"> 

And then it's ok !