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:

  1. <input name="prop[]"> - doesn't work saying invalid property 'prop[]' of bean class [...]: invalid index in property path 'prop[]'; nested exception java.lang.numberformatexception: input string: ""

  2. <input name="prop"> - not bind list-typed bean property, when multiple fields present.

  3. <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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -