开发者

Spring MVC - bind form elements to a List<Long>

开发者 https://www.devze.com 2023-03-24 00:47 出处:网络
Is it possible to bind a form element to a List<Long>开发者_开发百科? ie. <form:input path=\"formValues[0]\" /> binding to an element in List<Long> formValues; in the form backing o

Is it possible to bind a form element to a List<Long>开发者_开发百科?

ie. <form:input path="formValues[0]" /> binding to an element in List<Long> formValues; in the form backing object?

When I try this, it fails because Long does not have a default constructor new Long().

I've worked around it by creating a dummy holder class

class DummyLong {
    private Long value;
    ...
}

making the list in the formbacking object a List<DummyLong> and changing the form tag to <form:input path="formValues[0].value" /> but this seems unnecessarily hideous and I'm sure there must be a better way. Haven't been able to find it though.


Use List<Long> formValues with <form:input path="formValues" />

0

精彩评论

暂无评论...
验证码 换一张
取 消