我有一个非常特殊的问题。我正在用 Java 和 Spring MVC 开发一个 Web 应用程序。我有一行可以由用户在按下按钮时动态复制。每行大约有 10 个字段。我将这些行绑定为支持 bean 中的对象列表,并将此列表初始化为 bean 中的惰性列表。现在,它一直工作到现在,但用户尝试输入 12 行和第 12 行,即第 11 次迭代(从 0 开始的迭代),第 5 个字段变为空,尽管用户输入了值并且所有的其他字段保留其值。由于绑定发生在名称上,因此我检查了该字段的名称,它与同一行中的其余字段和其余行中的其余字段一致。我无法调试和纠正问题。这会影响生产中的代码。
我可以提供所需的任何代码片段。
有人可以帮我解决这个问题。提前致谢。
编辑:我尝试在不同的服务器上执行相同的代码,它在那里工作正常,但仍然存在于实时服务器上。而且问题似乎只在第 11 次迭代的第 5 场。会不会是服务器的问题
添加代码:
JSP:
<c:forEach items="${addProposal.requirements}" var="req" varStatus="status">
<!--Rest of the fields-->
<form:input path="requirements[${status.index}].sampleSize" id="r_sample${status.index}" value="${addProposal.requirements[status.index].maximumFeasibility}" class="inptform2" style="width:65px;" size="10" onchange="functions();"/>
<!--Rest of the fields-->
<td width="57" align="left" valign="middle" id="btn-close" class="btn-remove">' +
'<a href="javascript:void(0)"><img src="images/btncross.png" width="18" height="17" border="0" />' +
'</a>
</td>
</c:forEach>
Javascript:
$(document).ready(function(){
//Add more dynamic rows
$("#addMore").click(function() {
var tr_temp=$("#requirement tr:first").clone();
//rest of the fields code
tr_temp.find("#r_sample0").each(function() {
$(this).attr({
'id': function(_, id) { return 'r_sample' + i},
'name': function(_, name) { return 'requirements[' + i + '].sampleSize'},
'value': ''
});
}).end();
tr_temp.find("td:last").remove();
tr_temp.append(btn_close);
tr_temp.appendTo("#requirement");
i++;
});
//To remove a dynamically added row
$("#btn-close").live('click',function(){
doNotDel=false;
count=0;
//To fetch the values of the Input Fields
$(this).parent().find("input").each(function(){
count++;
var value = $(this).val();
var id=$(this).attr('id');
if(id.indexOf("r_total")==-1){
//Skip the minutes and currency column
if(id.indexOf("minutes")==-1 && id.indexOf("currencyValF")==-1 && id.indexOf("currencyVal")==-1){
if(value!=""){
doNotDel=true;
return false; //breaks the .each loop
}
}
}
});
if(doNotDel==false){
$(this).parent().remove();
}
});
});
豆:
private List<RequirementBean> requirements;
//in constructor
requirements = LazyList.decorate(
new ArrayList<RequirementBean>()
, new InstantiateFactory(RequirementBean.class));
控制器:
@RequestMapping(value="/addProposal", method=RequestMethod.POST)
public String addProposal(@ModelAttribute("addProposal") ProposalBean proposal, ModelMap model){
RequirementBean req;
List<RequirementBean> reqmtList;
System.out.println("Before empty rows");
reqmtList = proposal.getRequirements();
for(int i=0; i<reqmtList.size(); i++){
req = reqmtList.get(i);
if(req.getCountry()!=null){
System.out.println("sample size " + i + " :" + req.getSampleSize());
}
}
}
编辑:我尝试更改同一列中第 4 行的值,现在代码似乎可以工作。我仍然无法理解问题所在。
希望这能提供更多的清晰度。请帮我。