我正在使用 spring MVC。我的命令对象包含一个集合对象,如下所示
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;
}
}
这个控制器类,扩展了AbstractWizardFormController
我习惯于formBackingObject()
填充命令对象将其返回到表单
表格如下所示
<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>
这会在命令对象中显示集合中的值,并使我们能够删除、编辑和添加新行。
但我的问题是,删除命令对象中的集合中的相应对象并没有清除。因此,有不需要的 DIMENSIONSTONE 对象。我必须做什么来解决这个问题?请告诉我.......