我是 Spring MVC。我的控制器类扩展了 AbstractWizardFormController 类。
我的命令对象 UpdateStockBean 包含 List。我的命令类如下所示
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>