【发布时间】:2019-03-21 01:08:29
【问题描述】:
编辑现在我知道我的问题是由于this。该链接还提供了解决方案,但我似乎无法在第二个列表中弄清楚如何做到这一点。
我将首先向您展示我正在处理的代码结构。
这是 MyForm 类:
public class MyForm extends ValidatorForm {
private List<ADTO> aDTOList;
// getters and setters for aDTOList below
public ADTO getADTO(int index) {
if (aDTOList == null) {
aDTOList = new ArrayList<ADTO>();
}
if (aDTOList.size() - 1 < index) {
while (aDTOList.size() - 1 < index) {
aDTOList.add(new ADTO());
}
}
return aDTOList.get(index);
}
@Override
protected ActionErrors execValidate(ActionMapping mapping, HttpServletRequest request) {
// BODY NOT SHOWN FOR PRIVACY
}
@Override
public void reset(ActionMapping mapping, HttpServletRequest request) {
super.reset(mapping, request);
this.aDTOList = new ArrayList<ADTO>();
}
}
这里是 ADTO 类:
public class ADTO {
private List<BDTO> bDTOList;
// getters and setters for bDTOList below
}
这是 BDTO 类:
public class BDTO {
private String sample1;
private String sample2;
// getters and setters for sample1 and sample2 below
}
通过这样做,我已经成功地在 JSP 中显示了aDTOList 的内容:
<logic:iterate id="ADTO" name="MyForm" property="aDTOList" indexId="idxRes">
<logic:iterate id="BDTO" name="ADTO" property="bDTOList" indexId="idxLine">
<html:hidden name="BDTO" property="sample1" indexed="true"/>
<html:hidden name="BDTO" property="sample2" indexed="true"/>
</logic:iterate>
</logic:iterate>
现在我的问题是,每当我提交 aDTOList 内的表单 bDTOList 时都会变为空。aDTOList 的大小与我显示的原始列表相同,但唯一的区别是 @ 的所有元素aDTO 中的 987654330@ 为空。 aDTOList 的结构是这样的,如果aDTOList 的大小为2,每个ADTO 包含bDTOList,bDTOList 的大小也为2。
[[null, null],[null, null]]
因此,我认为我的问题是我的表单中没有getBDTO,但我不知道如何实现它。谁能帮助我如何实施它?或者有没有其他方法可以用原始数据填充bDTOList?
注意:我无法更改代码的结构,代码只是示例代码
【问题讨论】:
-
您是否尝试过在您的 html:hidden 属性中提供 value = "" 字段?
-
html:hidden 属性会渲染成输入属性,输入属性有实际值
标签: java spring spring-mvc jsp struts