私は非常に独特な問題を抱えています。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行目の値を変更してみましたが、コードが機能するようになりました。私はまだ何が問題なのか理解できません。
これがより明確になることを願っています。私を助けてください。