java - How to handle lists with multiple select in thymeleaf? -
i have multiple select this..
<select multiple="multiple" th:field="*{names}"> <option value="abc">abc</option> <option value="def">def</option> <option value="ghi">ghi</option> <option value="jkl">jkl</option> </select> where names name of list looks this..
list<string> names=new arraylist<>(); now, user select multiple names , set names list. consider have selected
abc
def
ghi
when submitting form, see info sent this..
names=abc&names=def&names=ghi however, want names[0]=abc&names[1]=def&names[2]=ghi.
p.s. don't want utilize ajax form sending.
why of import have submitted form's query string way? because processing form different framework other spring mvc?
based on tags of spring-mvc, spring expects names=abc&names=def&names=ghi. info names <select> form field, single form field multiple values. internally, spring correctly map names property form-backing bean.
to names[0]=abc&names[1]=def&names[2]=ghi, need 3 <select> elements in html represent each unique field name (i.e. names[0], names[1], etc), uncertainty want.
as far know, that's behavior of html , can't changed.
i did quick search , reminded php requires name of multi-select fields end in [] parsed array. that's php-only quirk. that's closest reason can think original requirement. however, have required instead: names[]=abc&names[]=def&names[]=ghi. , uncertainty can mimic spring/thymeleaf since not valid property name characters. see details: http://stackoverflow.com/a/11616681/1034436 (noting comments)
java spring spring-mvc thymeleaf
No comments:
Post a Comment