Has anybody dealt with a situation, that on the client side (html form) there is one type of field, that exist various times?
Like:
<input id="fileRef1" type="hidden"/>
<input id="fileRef2" type="hidden"/>
....
<input id="fileRefx" type="hidden"/>
so that the DTO would need something like String[] fileRefs;
I'm using spring framework, but I don't se开发者_JAVA百科e how could I use dataBinder or custom editor for that. Any suggestions please?
Spring binding will allow you use syntax like
<input name="arrayOfStrings[0]" type="hidden" value="xxx">
<input name="arrayOfStrings[1]" type="hidden" value="xxx">
Just be sure your DTO array is the correct size. You can also use org.springframework.util.AutoPopulatingList if you do now know at form generation time how many elements your collection will have.
Give the same field name to all fields
<input id="fileRef1" name="fileRefs" type="hidden"/>
<input id="fileRef2" name="fileRefs" type="hidden"/>
....
so that fileRefs value will save in String array like String[] fileRefs in order
You should probably take a look at these links :
SO
mattfleming
mattfleming - why ?
eggsylife
lifeinide
richardadamdean
精彩评论