Announcement Announcement Module
Collapse
No announcement yet.
Create Command object with dynamic input fields Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create Command object with dynamic input fields

    Hi

    I'm using Spring MVC, and I'm creating a register form for users. The user can submit an arbitrary number of addresses and telephone numbers. I add such fields to the page using javascript: I clone a template element containing all the input fields for a new address and telephone.
    The fields names and ID's are modified when cloned, in order to avoid duplicity: 'street_name' is renamed to 'street_name1', 'district_name' is renamed to 'district_name1' and so on, the suffix number being a counter, incremented for each new address/telephone block.
    At form submission, the numbers obtained for the blocks of address/telehone data may be missing some indexes, because blocks can be removed (e.g: I get back address fields numbered 1, 3 and 4, and phone fields numbered 2, 3, 4 and 6).

    My question is how can I turn these various telephone and address fields into some field like Address[] and Telehone[] in my command object?
    I believe this is very simple to do, but I couldn't find out how. I thought it was done using propery editors, but I had no success on this.

    Thanks!

  • #2
    Hi

    I'm still around this issue.
    In one of my tests, I was able to populate the address fields using code="address[0].streetName". It correctly sets the street name for the first address field, but I had to make my address command object instantiate the array with address fields when constructed:

    Code:
    private Address[] addresses = new Address[]{new Address()};
    I can't use this, because address field indexes will not be surely sequential, and I don't know how much addresses the user will input, this fixed size array is not enough.

    Please, how can I do this?

    Thanks!

    Comment


    • #3
      well, nobody showed up, but I found a solution to this. for those with the same issue, see this topic:
      http://forum.springsource.org/showthread.php?t=26795

      Comment

      Working...
      X