I have a slightly different problem.
I have a hibernate domain object as follows
Code:
public class TestModel
{
Set s;
......getters and setters
}
The HashSet in the TestModel contains the following objects (say 4 of them)
Code:
public class City
{
private String city;
private String name;
......getters and setters
}
I use the formBackingObject to populate the values so that they get displayed on the form
Code:
protected Object formBackingObject(HttpServletRequest arg0)
throws Exception
{
TestModel testModel = new TestModel();
Set s = new HashSet();
City city = new City();
city.setCity("A");
city.setName("B");
s.add(city);
city = new City();
city.setCity("C");
city.setName("D");
s.add(city);
city = new City();
city.setCity("E");
city.setName("F");
s.add(city);
city = new City();
city.setCity("G");
city.setName("H");
s.add(city);
testModel.setS(s);
return testModel ;
}
The jsp page uses this code to bind and show the values
HTML Code:
<spring:bind path="testModel.s">
<core:forEach items="${status.value}" var="obj">
<input type="text" value="<core:out value="${obj.city}"/>" name="<core:out value="${status.expression}"/>City">
<input type="text" value="<core:out value="${obj.name}"/>" name="<core:out value="${status.expression}"/>Name">
</core:forEach>
<div id="myDiv">
<input type="hidden" value="0" id="theValue" />
</div>
<tr>
<input type="button" name="addRow" value="add" onclick="addElement('<core:out value="${status.expression}"/>City','<core:out value="${status.expression}"/>Name');">
</tr>
</spring:bind>
After getting displayed, the jsp now contains
The values within the objects in the "languages" HashSet are displayed in the jsp as
City Name
--- -----
A B
C D
E F
G H
----------
| AddRow | <-- The add row button
----------
The actual "names" of the textboxes for City and Name come out to be "sCity" and "sName" respectively.
By using the "addRow" another row is dynamically inserted to the table with the same names as the previous textboxes. Within the jsp these new textboxes come within the <spring:bind> tag.
But when the form is submitted these do not show up in the model. Which means that, if there are already 4 cities in the model and i add a fifth dynamically, the fifth is not shown when displayed within the onSubmit() method after being extracted from the model.
Code:
protected ModelAndView onSubmit(HttpServletRequest arg0,
HttpServletResponse arg1, Object arg2, BindException arg3)
throws Exception
{
TestModel testModel = (TestModel) arg2;
System.out.println("hash SIZE = " + tm.getS().size());
.....
}
The size is still shown as 4 instead of 5.
I have been searching without success in this forum for a solution to this problem .
What am I doing wrong ?
Someone help me out on this.