我是Spring MVC.My控制器类扩展了AbstractWizardFormController类。
我的命令对象UpdateStockBean包含List.My命令类,如下所示
public class UpdateStockBean {
@SuppressWarnings("rawtypes")
private List dimensionStones =
LazyList.decorate(new ArrayList(),FactoryUtils.instantiateFactory(DimensionStoneBean.class));
String productiondate;
long openbalance;
public UpdateStockBean() {
super();
}
@SuppressWarnings("rawtypes")
public List getDimensionStones() {
return dimensionStones;
}
public void setDimensionStones(@SuppressWarnings("rawtypes") List dimensionStones) {
this.dimensionStones = dimensionStones;
}
}
我已经使用表单支持对象来填充JSP中的字段。它看起来像下面。
protected Object formBackingObject(HttpServletRequest request)throws Exception {
UpdateStockBean updateStockBean=new UpdateStockBean();
updateStockBean.setDimensionStones(dimensionStoneBeans);//here dimensionStoneBeans is a list
return updateStockBean;
}
我的问题出在我的jsp
中 <c:forEach items="${updateStockBean.dimensionStones}" var="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}" cssClass="controlStock"/></td>
<td><form:input path="dimensionStones[${i.index}].breadth" id="breadth${i.index}" cssClass="controlStock"/></td>
<td><form:input path="dimensionStones[${i.index}].height" id="height${i.index}" 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}" cssClass="check"/></td>
<td><a href="#" class="removeDimensionStone"><img src="images/plus3.png" width="20" height="20" title="Remove Dimension Stone"/></a></td>
</tr>
</c:forEach>
<c:if test="${empty updateStockBean.dimensionStones}">
<tr class="dimensionStone defaultRow">
<td><input type="text" name="dimensionStones[].stoneNo" value="" Class="controlStock"/></td>
<td><input type="text" name="dimensionStones[].length" value="" Class="controlStock"/></td>
<td><input type="text" name="dimensionStones[].breadth" value="" Class="controlStock"/></td>
<td><input type="text" name="dimensionStones[].height" value="" Class="controlStock"/></td>
<td><input type="text" name="dimensionStones[].dimension" value="" Class="controlStock"/></td>
<td><input type="checkbox" name="dimensionStones[].isIssued" value="Yes" 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>
$ {updateStockBean.dimensionStones}为空。如何在我的jsp中引用由formBacking()方法填充的 updateStockBean 对象。请解决我的问题
servlet conf在下面给出
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="updateStock.nic">UpdateStockController</prop>
<props>
</property>
</bean>
<bean id="UpdateStockController" class="mams.web.UpdateStockController">
<property name="commandName"><value>updateStock</value></property>
<property name="commandClass"><value>nic.mams.web.beans.UpdateStockBean</value>
</property>
<property name="stockRegisterService" ref="StockRegisterService"></property>
<property name="dimensionStoneService" ref="DimensionStoneService"></property>
<property name="validator" ref="UpdateStockValidator"></property>
<property name="pages">
<list>
<value>addOrEditOpenDimensionStone</value> //this value corresponds to my jsp
</list>
</property>
</bean>
答案 0 :(得分:0)
这里 updateStockBean.dimensionStones ,updateStockBean必须是命令名,而不是formbackingObject()方法返回的对象的名称。这是
<form commandname="updateStock">
<c:forEach items="${updateStock.dimensionStones}" var="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}" cssClass="controlStock"/></td>
<td><form:input path="dimensionStones[${i.index}].breadth" id="breadth${i.index}" cssClass="controlStock"/></td>
<td><form:input path="dimensionStones[${i.index}].height" id="height${i.index}" 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}" cssClass="check"/></td>
<td><a href="#" class="removeDimensionStone"><img src="images/plus3.png" width="20" height="20" title="Remove Dimension Stone"/></a></td>
</tr>
</c:forEach>
<c:if test="${empty updateStock.dimensionStones}">
<tr class="dimensionStone defaultRow">
<td><input type="text" name="dimensionStones[].stoneNo" value="" Class="controlStock"/></td>
<td><input type="text" name="dimensionStones[].length" value="" Class="controlStock"/></td>
<td><input type="text" name="dimensionStones[].breadth" value="" Class="controlStock"/></td>
<td><input type="text" name="dimensionStones[].height" value="" Class="controlStock"/></td>
<td><input type="text" name="dimensionStones[].dimension" value="" Class="controlStock"/></td>
<td><input type="checkbox" name="dimensionStones[].isIssued" value="Yes" 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>
</form>