I am working with spring MVC.My command object contains a collection object,it looks like as follows
public class DimensionStoneBean {
int stoneNo;
float length;
float breadth;
float height;
float dimension;
String isIssued;
public int getStoneNo() {
return stoneNo;
}
public void setStoneNo(int stoneNo) {
this.stoneNo = stoneNo;
}
public float getLength() {
return length;
}
public void setLength(float length) {
this.length = length;
}
public float getBreadth() {
return breadth;
}
public void setBreadth(float breadth) {
this.breadth = breadth;
}
public float getHeight() {
return height;
}
public void setHeight(float height) {
this.height = height;
}
public float getDimension() {
return dimension;
}
public void setDimension(float dimension) {
this.dimension = dimension;
}
public String getIsIssued() {
return isIssued;
}
public void setIsIssued(String isIssued) {
this.isIssued = isIssued;
}
}
public class UpdateStockBean {
@SuppressWarnings("rawtypes")
private List dimensionStones =
LazyList.decorate(new LinkedList(),FactoryUtils.instantiateFactory(DimensionStoneBean.class));
long openbalance;
public UpdateStockBean() {
super();
}
@SuppressWarnings("rawtypes")
public List getDimensionStones() {
return dimensionStones;
}
public void setDimensionStones(@SuppressWarnings("rawtypes") List dimensionStones) {
this.dimensionStones = dimensionStones;
}
public long getOpenbalance() {
return openbalance;
}
public void setOpenbalance(long openbalance) {
this.openbalance = openbalance;
}
}
The controller class for this,extends AbstractWizardFormController
I have used formBackingObject()
to populate the command object return it to form
The form looks like as follows
<form:form commandName="updateStock" method="post" name="stockEntry" action="updateStock.nic" id="updateStock">
<br><br><br>
<table border="1" width="700">
<tr>
<td class="textClr1" align="left" width="50"><nobr>Total No Of Stones</nobr></td>
<td colspan="6"><form:input tabindex="1" path="openbalance" id="openbalance" cssClass="controlStock"/></td>
</tr>
<tr>
<td></td>
<td colspan="6"><form:errors cssClass="error" path="openbalance"/></td>
</tr>
</table>
<table>
<tr>
<td colspan="3">
<table border="1" width="400">
<tbody id="dimensionList">
<c:forEach var="DimensionStones" items="${updateStock.dimensionStones}" varStatus="i" begin="0">
<tr class="dimensionStone">
<td><form:input path="dimensionStones[${i.index}].stoneNo" id="stoneNo${i.index}" cssClass="controlStock"/></td>
<td><form:input path="dimensionStones[${i.index}].length" id="length${i.index}" onchange="findDimension(this.id)" cssClass="controlStock"/></td>
<td><form:input path="dimensionStones[${i.index}].breadth" id="breadth${i.index}" onchange="findDimension(this.id)" cssClass="controlStock"/></td>
<td><form:input path="dimensionStones[${i.index}].height" id="height${i.index}" onchange="findDimension(this.id)" cssClass="controlStock"/></td>
<td><form:input path="dimensionStones[${i.index}].dimension" id="dimension${i.index}" cssClass="controlStock"/></td>
<td><form:checkbox path="dimensionStones[${i.index}].isIssued" id="isIssued${i.index}" value="" cssClass="check"/></td>
<td><a href="#" class="removeDimensionStone"><img src="images/cross1.jpg" width="20" height="20" title="Remove Dimension Stone"/></a></td>
</tr>
</c:forEach>
<tr>
</tr>
<c:if test="${empty updateStock.dimensionStones}">
<tr class="dimensionStone defaultRow">
<td><input type="text" name="dimensionStones[].stoneNo" value="" id="stoneNo" Class="controlStock"/></td>
<td><input type="text" name="dimensionStones[].length" value="" id="length" onchange="findDimension(this.id)" Class="controlStock"/></td>
<td><input type="text" name="dimensionStones[].breadth" value="" id="breadth" onchange="findDimension(this.id)" Class="controlStock"/></td>
<td><input type="text" name="dimensionStones[].height" value="" id="height" onchange="findDimension(this.id)" Class="controlStock"/></td>
<td><input type="text" name="dimensionStones[].dimension" value="" id="dimension" disabled="disabled" Class="controlStock"/></td>
<td><input type="checkbox" name="dimensionStones[].isIssued" value="Yes" id="isIssued" Class="controlStock"/></td>
<td><a href="#" class="removeDimensionStone"><img src="images/cross1.jpg" width="20" height="20" title="Remove Dimension Stone"/></a></td>
</tr>
</c:if>
</tbody>
</table>
</td>
</tr>
</table>
<table border="1" width="600">
<tr>
<td colspan="3" align="left"><a href="#" id="addDimensionStone"><img src="images/plus3.png" width="20" height="20" title="Add Dimension Stone"/></a></td>
</tr>
<tr></tr>
<tr></tr>
<tr>
<td colspan="3" align="center" width="200" height="180">
<input type="submit" name="_target0" value="Submit" class="butn" />
</td>
</tr>
</table>
</form:form>
This display the values in collection in command object and enable us to deleting, editing and adding new rows.
But my problem is,deleting does not clear the corresponding object in collection in command object.As a result threre is unwanted DIMENSIONSTONE objects.What i have to do ,to solve this problem?please advice me .......