メニュー
人気記事
明細一覧に入力フィールドを作成し、同じ項目を複数登録する時、ActionFormのArrayListにIOできると便利。ArrayListの要素は自作のClassのインスタンスが使用可能。
[Java]public class Detail{String detailField1="abcdefg" ;//getter & setter ・・・}public class MyAction(...){...ArrayList al = new ArrayList();al.add(new Detail()); //必要な数だけ繰り返すal.add(new Detail());al.add(new Detail());myForm.set("detail", al);}
[JSP]<logic:iterate id="detail" name="myForm"property="detail" ><html:text name="detail" property="detailField1" indexed="true"/></logic:iterate>[出力]<input type="text" name="detail[0].detailField1" value="abcdefg" /><input type="text" name="detail[1].detailField1" value="abcdefg" /><input type="text" name="detail[2].detailField1" value="abcdefg" />[おまけのJS]function getListObject(list, field,index){return document.forms[0].elements[list+"[" + index + "]." + field ];}
注意点
・logic:iterateのid(html:textのnameでもある)とActionFormのListの変数を同じ名前にする。・indexedをtrueにする。・あらかじめリストに必要な数だけ要素を追加しておく
参考
http://civic.xrea.jp/2006/06/09/struts-using-list/
このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー と 利用規約 が適用されます。
1文字以上入力してください
本文は少なくとも1文字以上必要です。
1文字以上入力してください。