4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

StrutsのActionFormでList型を利用

Last updated at Posted at 2013-12-10
xxxForm.java
    private List<String> tags = new ArrayList<String>();

/** リクエストパラメータから設定 */
    public void setTags(int index, String value) {
        tags.add(index,  value);
    }
/** getter **/
    public List<String> getTags() {
        return tags;
    }

xxx.do?tags[0]=aaa&tags[1]=bbb

xxxForm2

    private List<DataBean> dataObjectList = new ArrayList<DataBean>();

/** リクエストパラメータから設定 */
    public DataBean getDataObjects(int index) {
        while (this.dataObjectList.size() <= index) {
            this.dataObjectList.add(new DataBean());
        }
        return this.dataObjectList.get(index);
    }
/** リクエストパラメータから設定 */
    public Object[] getDataObjects() {
        return dataObjectList.toArray();
    }
/** getter **/
    public List<DataBean> getDataObjectList() {
        return dataObjectList;
    }

xxx.do?dataObjects[0].methodA=aaa&dataObjects[0].methodB=bbb
Listの中オブジェクトにする場合はこんな感じらしい
変数はnew ArrayList()しとかないとエラーします

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?