Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Tomasz Romanowski
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's inside the c:foreach tag?

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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic