开发者

Domain Transfer Object for a html form with various count of fields

开发者 https://www.devze.com 2023-02-13 02:41 出处:网络
Has anybody dealt with a situation, that on the client side (html form) there is one type of field, that exist various times?

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

0

精彩评论

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