File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes how to bind a table of items in JSP form to a List attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "how to bind a table of items in JSP form to a List attribute" Watch "how to bind a table of items in JSP form to a List attribute" New topic
Author

how to bind a table of items in JSP form to a List attribute

Tomasz Romanowski
Ranch Hand

Joined: May 06, 2009
Posts: 38
In my model I have an object with a List type attribute called parts and a few primitive ones. In my JSP I want to display this list and and allow the user to add/delete to/from this list. The problem is when the form gets submitted only the primitive attributes get bound. The List attribute remains null.
To illustrate what I'm looking for, in JSF they have a "datatable" tag that automatically binds the item table to the "parts" attribute:

<%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<h:dataTable id="parts value="#{theObject.parts}" var="item" >
.........
</h:dataTable>

In spring I don't see any equivalent of "datatable". Of course, I can easily display the table using the JSTL foreach but the items are not bound when the form is submitted:

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

<c:forEach var="part" items="${theObject.parts}" varStatus="status">
-----
</c:forEach>
Tomasz Romanowski
Ranch Hand

Joined: May 06, 2009
Posts: 38
Anybody?
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

What's inside the c:foreach tag?

To bind to specific field(s) you can do something like



-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to bind a table of items in JSP form to a List attribute