Results 1 to 3 of 3

Thread: Wrong mapping between FORM and Back-en object when having embedded collections

  1. #1
    Join Date
    Mar 2009
    Posts
    2

    Unhappy Wrong mapping between FORM and Back-en object when having embedded collections

    Hi all,
    here is a problem I had for several days now and couldn't find any solution, maybe someone can help me.
    When I submit a request (though Spring Web Flow), the mapping between the FORM and the back-end object is not correctly performed when mapping embedded collections.

    Here is the HTML code generated:


    <FORM id="myObjectForm" action="/myapplicationWeb-1.0-SNAPSHOT/admin/client/updateClient.htm?execution=e2s2"
    method="post">
    <H3>Client Attributes</H3>
    <BR />
    <BR />
    <TABLE>
    <TBODY>
    <TR>
    <TD id="dynForm0">
    <HR style="COLOR: #ba3209; HEIGHT: 3px" />
    <INPUT type="hidden" name="selectedSourceAttributes[0].sourceName" value="AuthoritiesRegulation" />
    <TABLE>
    <TBODY>
    <TR style="BACKGROUND-COLOR: #d6d2c4">
    <TD>
    <SELECT id="selectedSourceAttributes0.mappedAttributes0.ma ppedAttributeNames"
    multiple name="selectedSourceAttributes[0].mappedAttributes[0].mappedAttributeNames">
    <OPTION value="CODE1">VALUE1</OPTION>
    <OPTION value="CODE2">VALUE2</OPTION>
    <OPTION value="CODE3">VALUE3</OPTION>

    </SELECT>
    <INPUT type="hidden"
    name="_selectedSourceAttributes[0].mappedAttributes[0].mappedAttributeNames" value="1" />
    </TD>
    <TD>
    <INPUT id="selectedSourceAttributes0.mappedAttributes0.cu stomAttributeName"
    name="selectedSourceAttributes[0].mappedAttributes[0].customAttributeName" value="myInputValue00" />
    </TD>
    </TR>
    </TBODY>
    </TABLE>
    </TD>
    </TR>
    <TR>
    <TD id="dynForm1">
    <HR style="COLOR: #ba3209; HEIGHT: 3px" />
    <INPUT type="hidden" name="selectedSourceAttributes[1].sourceName" value="Intranet" />
    <TABLE>
    <TBODY>
    <TR style="BACKGROUND-COLOR: #d6d2c4">
    <TD>
    <SELECT id="selectedSourceAttributes1.mappedAttributes0.ma ppedAttributeNames"
    multiple name="selectedSourceAttributes[1].mappedAttributes[0].mappedAttributeNames">
    <OPTION value="CODE1">VALUE1</OPTION>
    <OPTION value="CODE2">VALUE2</OPTION>
    <OPTION value="CODE3">VALUE3</OPTION>

    </SELECT>
    <INPUT type="hidden"
    name="_selectedSourceAttributes[1].mappedAttributes[0].mappedAttributeNames" value="1" />
    </TD>
    <TD>
    <INPUT id="selectedSourceAttributes1.mappedAttributes0.cu stomAttributeName"
    name="selectedSourceAttributes[1].mappedAttributes[0].customAttributeName" value="myInputValue10" />
    </TD>
    </TR>
    </TBODY>
    </TABLE>
    </TD>
    </TR>
    </TBODY>
    </TABLE>
    <TABLE border="1">
    <TBODY><TR><TD><INPUT type="submit" name="_eventId_next" value="Next" /></TD></TR></TBODY>
    </TABLE>
    <INPUT id="sourceCounter0" type="hidden" name="sourceCounter0" value="1" />
    </FORM>



    myObjectForm contains:
    -> List<SourceAttributeForm> selectedSourceAttributes;
    A SourceAttributeForm contains:
    --> List<MappedAttributeForm> mappedAttributes and a sourceName (String)
    A MappedAttributeForm contains :
    --> String customAttributeName and a List<String> mappedAttributeNames



    And when the request is submitted, the data mapped in myObjectForm is not correct, actually I get:
    selectedSourceAttributes[0].mappedAttributes[0].customAttributeName="myInputValue10"
    selectedSourceAttributes[1].mappedAttributes[0].customAttributeName="myInputValue10"

    instead of having:
    selectedSourceAttributes[0].mappedAttributes[0].customAttributeName="myInputValue00"
    selectedSourceAttributes[1].mappedAttributes[0].customAttributeName="myInputValue10"

    Can anyone explain what's going on here?

    Thanks in advance,

    Giorgio

  2. #2

    Default

    I'm not sure we could tell based on what you've posted here but I have some suggestions:

    1) It might be worthwhile to look at the actual HttpServletRequest that's sent by the browser (lots of ways to find this - I usually set a breakpoint in the debugger on the setter in question and then walk up the stack until I get to the doPost call) That will determine if this is a problem in the HTML (it's generating the wrong stuff) or in the binding somehow.

    2) I've had this problem in the past when I had the same object in the list twice (because then the setter is called twice and everything ends up with the last value)

    3) If none of that works, I might add some logging code (or set the debugger breakpoint) in the setter to see what values it's being called with...

  3. #3
    Join Date
    Mar 2009
    Posts
    2

    Default

    Thanks for the response....indeed, I was looking at the wrong place to solve this problem.
    The problem was that during the rendering of the form, I initialized the 'selectedSourceAttributes' collection with the SAME instance of the object (new MappedAttribute() ).
    I just had to initialize this collection with different instances of MappedAttribute object.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •