Results 1 to 4 of 4

Thread: How to display select box for property in list of object

  1. #1
    Join Date
    May 2010
    Posts
    15

    Default How to display select box for property in list of object

    Hi,

    Could someone help me on how to set select box for property in the list of object? Here is how my command object looks like -
    Code:
    public class SampleClass{
       private int integermember;
       private boolean booleanmember;
       private Set<AlleyNames> names;
    }
    
    public class AlleyNames {
       private int id;
       private String realName;
       private String fakeName;
    }
    I am using SampleClass as command object.

    In my JSP, I can get values for integermember, booleanmember etc easily as following -

    Code:
    <form:label path="booleanmember" />
    <form:hidden path="integernumber"/>
    How do I display values inside Set of AlleyNames? I need to loop through it and display it. How can I use <c:forEach> for this? I need to display the realName and fakeName values in different columns something like -

    Code:
    booleanmember - true
    integernumber - 5
    
    Real Name       Fake Name
    abc                   xyz
    123                   456
    Any suggestions?

    Thanks,

  2. #2
    Join Date
    May 2010
    Posts
    15

    Default

    any suggestions?

  3. #3
    Join Date
    May 2010
    Posts
    15

    Default

    ok, so looping through is not a big deal.
    Code:
    				<c:forEach items="${sampleObj.names}" var="aname" varStatus="loopStatus">
    				<tr>
    					<td>
    						<c:out value="${aname.realName}"></c:out>
    					</td>
    					<td><c:out value="${aname.fakeName}"></c:out></td>
    				</tr>
    				</c:forEach>
    But how do I bind each element with individual index element of the object? That is, if instead of just displaying on screen, I want to show in text box and whatever values user update, I want it to be updated in corresponding object. So, if there are two rows I display -

    Code:
    realname1               fakename1      //names[0]
    realname2               fakename2      //names[1]

    Whatever user updates in text fields, I want to bind it to corresponding AlleyNames element inside SampleClass object. How can I do that?

  4. #4
    Join Date
    May 2010
    Posts
    15

    Default

    Can someone please answer this?

    Code:
    public class SampleClass{
       private int integermember;
       private boolean booleanmember;
       private Set<AlleyNames> names;
    }
    
    public class AlleyNames {
       private int id;
       private String realName;
       private String fakeName;
    }
    From above code, all I want to know is, how can I bind all names (Set of AlleyNames) to SampleClass in a JSP if I am using SampleClass as a command object?

    I will really appreciate any help.

Posting Permissions

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