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

  • creating POJO

    Hi

    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:

    Code:
    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:

    Code:
    <B>Previous Visits:</B>
    <TABLE border="true">
      <TH>Date</TH><TH>Description</TH>
      <c:forEach var="visit" items="${visit.pet.visits}">
        <c:if test="${!visit.new}">
          <TR>
            <TD><fmt:formatDate value="${visit.date}" pattern="yyyy-MM-dd"/></TD>
            <TD><c:out value="${visit.description}"/></TD>
          </TR>
        </c:if>
      </c:forEach>
    </TABLE>
    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

    Comment

    Working...
    X