Results 1 to 6 of 6

Thread: command object having List field

  1. #1
    Join Date
    Jun 2006
    Posts
    11

    Default command object having List field

    Hi,
    Am having a command object which has a List type field. For example, Customer can have multiple addresses and so am having it as a List
    <code>
    public class Customer{
    private String customerName;
    private List<Address> address;

    --getters and setters--
    }
    </code>

    My question is to how do i map the form fields with this command object. My form will have fields for entering 2 addresses. What should be given in the path attribute of the <form:input tag.

    any help is appreciated.

    Thanks

  2. #2
    Join Date
    Mar 2006
    Posts
    312

    Default

    Example
    Code:
    <form:input path="address[0].addressLine1"/>
    <form:input path="address[0].addressLine2"/>
    <form:input path="address[0].zipCode"/>
    <form:input path="address[1].addressLine1"/>
    <form:input path="address[1].addressLine2"/>
    <form:input path="address[1].zipCode"/>

  3. #3
    Join Date
    Jun 2006
    Posts
    11

    Default

    Hi,
    still its not working,getting the following error

    Invalid property 'address[0]' of bean class
    Cannot access indexed value of property referenced in indexed property path 'address[0]': returned null

    So i tried initializing the list as
    private List<Remark> remark = new ArrayList();

    Invalid property 'remark[0]' of bean class
    Index of out of bounds in property path 'address[0]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

    any help is appreciated.

    Thanks

  4. #4
    Join Date
    Mar 2006
    Posts
    312

    Default

    If you know there's only going to be two Address items in the array you should add them after instantiation.
    Code:
    private List<Address> addresses = new ArrayList();
    addresses.add(new Address());
    addresses.add(new Address());

  5. #5
    Join Date
    Jun 2006
    Posts
    11

    Default page has become very slow

    Thanks it worked, but another problem. If i add more combo boxes, it makes the page very slow, it takes ever to load the page if it has 3 combo boxes whose values are fetched from db and populated in the referenceData method. Following is the jsp am using to load the combo boxes

    <tr><td>Status</td><td>:<form:select path="status"><form:option value="-1">SELECT...</form:option>
    <c:forEach var="item" items="${cStatus}"><form:option value="${item}">${item}</form:option></c:forEach></form:select> </td></tr>

    Likewise i have 4 more combo boxes

    Can someone tell me why the page is taking ever to load it, sometimes timeout error?If i remove all the combo boxes, the page is fast with all other form fields

    any help is appreciated

    thanks

  6. #6
    Join Date
    May 2008
    Posts
    12

    Question I've the same situation but

    Hi, As stated above, I have a situation where the Command object has a List field.

    On the form I have check boxes and the selected check box items should map to the List field of the command object.

    Can anybody explain How to achieve this.


    Code: -
    ----------- Command Object --------------


    public class PlayerGroup {

    private String name;
    private List<Player> teamsAssociated;

    ...
    ....
    .....
    ......
    }


    ------------- JSP ---------------------
    .
    .
    .
    <c:forEach var="player" items="${playerList}">
    <tr>

    <td height="20" class="labelSmall"><form:checkbox path="teamsAssociated" value="${player}" label="${player.name}"></form:checkbox></td>
    <td align="left"><c:out value="${player.name}"/></td>
    </tr>
    </c:forEach>




    In the above code the form does not even being Submitted.

    Please give your suggestions.

Posting Permissions

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