Announcement Announcement Module
No announcement yet.
creating POJO Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • creating POJO


    I am new to Spring framework and a newbie in Java too. I am having an issue that I want to solve.

    In my object, which I want to display on the front end, there are few properties which have multiple values. For example, for a person, his country and state. As these properties values which can be displayed as a drop down list, I am not able to figure out how to implement them such that I can display them on the front end.

    Do I need to create another object? or, is there any other way possible.
    How do I do it?

    Please help

  • #2
    Hi GameOne,

    Not sure if I completely understand your question, but if an object can have multiple values and you want to display them, I would think you would want some Collection object (probably either a List or a Set) reference in the object. For example, assuming that a Person can have multiple Countries:

    public class Person {
       private Set<Country> countries;
       public Set<Country> getCountries() {
          return this.countries;
       public void setCountries(Set<Country> countries) {
          this.countries = countries;
    Then in your view page, iterate over the Collection. The following code is taken from the PetClinic sample application's war/WEB-INF/jsp/visitForm.jsp file:

    <B>Previous Visits:</B>
    <TABLE border="true">
      <c:forEach var="visit" items="${}">
        <c:if test="${!}">
            <TD><fmt:formatDate value="${}" pattern="yyyy-MM-dd"/></TD>
            <TD><c:out value="${visit.description}"/></TD>
    In the above case, the view is iterating over a pet's Set of Visits.

    So by having a Set of Country objects in a Person, you can then iterate over the Countries in your view via: person.countries. There are other issues, such as how to provide the Person object to the view for outputting, but that is a different story.

    If this did not answer your question, please re-post.

    -Arthur Loder