简体   繁体   中英

JSTL: for Each loop to iterate over collection

following is my snippet, which was working good untill I migrated from spring 2 to spring 3 and Jstl 1.1 to jstl 1.2. Now, its not working and keep on giving the error fEvents cannot found on object location

 <c:forEach items="${location.fEvents}" var="item" varStatus="loop">
    <tr><td><form:input path="fEvents[${loop.index}].hostName" size="30" maxlength="200"/></td>
    <td><form:input path="fEvents[${loop.index}].directory" size="30" maxlength="200"/></td>
    <td><form:input path="fEvents[${loop.index}].userName" size="20" maxlength="20"/></td>
    <td><form:input path="fEvents[${loop.index}].password" size="20" maxlength="20"/></td>
    </tr>
 </c:forEach>

need to iterate the ftpEvents and show them on jsp Any suggestion is appreciated!!!

It looks like the object called "location" does not have an fEvents property. Is it actually called ftpEvents? Do you need to just change the variable name?

Even with that, though, you'll probably want to do something more like this:

 <c:forEach items="${location.ftpEvents}" var="item">
    <tr><td><form:input path="item.hostName" size="30" maxlength="200"/></td>
    <td><form:input path="item.directory" size="30" maxlength="200"/></td>
    <td><form:input path="item.userName" size="20" maxlength="20"/></td>
    <td><form:input path="item.password" size="20" maxlength="20"/></td>
    </tr>
 </c:forEach>

...you don't need to even use the loop.index at all, if I'm interpreting your code correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM