LoginSignup
1
1

More than 5 years have passed since last update.

Spring MVCで繰り返し項目の値を受け取るForm

Last updated at Posted at 2016-12-14

String[] でも受け取れるみたいだけど、lazyListで実装すればPHPっぽく扱えて便利じゃね?という。
※以下、commons-collectionsは3系を使用。4系だとインターフェースが変わっている(良くなっている)っぽい。

SampleForm.java
public class SampleForm {
    private List<String> valueList = ListUtils.lazyList(new ArrayList(), new Factory() {
        public Object create() {
            return new String();
        }
    });

    public List<String> getValueList() {
        return valueList;
    }

    public void setValueList(List<String> valueList) {
        this.valueList = valueList;
    }
}
sample.jsp
<form:input path="valueList[0]"/>
<form:input path="valueList[1]"/>
<form:input path="valueList[2]"/>
1
1
1

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
1
1