Search code examples
javadisplaytag

How to process an object array of a class in display tag library



I am using the Display Tag Library, Here my problem is I need to process and print an object array using display tag library.
I will explain my problem, I have two classes named

    public class StudentAddress {
    private String street;
    private String city;

    public String getStreet() {
        return street;
    }
    public void setStreet(String street) {
        this.street = street;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }

}

And second class

import java.util.List;

public class Student {

    private int id;
    private String firstName;
    private String lastName;
    private String gender;
    private String city;
    private List<String> interests;
    private StudentAddress[] address;

    public StudentAddress[] getAddress() {
        return address;
    }
    public void setAddress(StudentAddress[] address) {
        this.address = address;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getGender() {
        return gender;
    }
    public void setGender(String gender) {
        this.gender = gender;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public List<String> getInterests() {
        return interests;
    }
    public void setInterests(List<String> interests) {
        this.interests = interests;
    }

}


so Here using display tag I need to display array of StudentAddress in the jsp page, I tried by googling but not found any sample to process the object array sp need help to process this. Thanks in advance


Solution


  • Finally I got the Solution we can use the display tag in this manner

    <display:table name="studentobj">
    <display:column property="id" title="StudentId"/>
    <display:column property="firstname" title="FirstName"/>
    <display:column title="Student Address">
    <%-- it will displays all the address objects properties if we need some we may user column tags inside table tag--%>
        <display:table name="studentobj.address"> 
        </display:table>
    </display:column>
    </display:table>