Easy way to submit an array field with Spring MVC forms? -
i have form list of nested fieldsets corresponding collection of objects, backed form object server-side. fieldsets can added or removed client-side. want submit form without caring object indices or sparse lists in command object.
here's controller method code:
@postmapping("/foobar") public string dopost(foobarform form) { //... }
in php, rails etc it's easy:
<input name="prop[]">
, , automatically populate $_post["prop"]
values.
working spring mvc, tried these things:
<input name="prop[]">
- doesn't work sayinginvalid property 'prop[]' of bean class [...]: invalid index in property path 'prop[]'; nested exception java.lang.numberformatexception: input string: ""
<input name="prop">
- not bind list-typed bean property, when multiple fields present.<input name="prop[${i}]">
- implies hassle sparse list , index handling, both client-side , server-side. not right way things when working powerful web framework.
i'm wondering why can't use []
in property name , let spring create list automatically? asked three times on spring jira without reasonable responses.
spring form binding makes more easy. need add list object in bean , bind in jsp using spring form.
class foobarform { list<string> prop; }
in jsp, if need show/edit value @ once <form:input path="prop" />
.if want show 1 one use indexing<form:input path="prop[0]" />
. use proper commandname in form. work.
Comments
Post a Comment