I have a Servlet which is called upon an Action and this Servlet is suppose to return a List of Objects. Now by having the Data Structure at the end of my Post my Servlet calls the Person.fetch()
which returns an list/array of Persons.
I want my Java Server Face to iterate through this list and call the getPresentation method on each object.
Is this possible and if so, how?
public class Person
{
private String name;
private String surname;
private int age;
/// -- GET --- ///
public String getName() { return name; }
public String getSurname() { return surname; }
public int getAge() { return age; }
/// -- SET --- ///
public void setName(String name) { this.name = name; }
public void setSurname(String surname) { this.surname = surname; }
public void setAge(int age) { this.age = age; }
/// -- OPERATIONS --- ///
public String getPresentation()
{
return "Hi, I am " + getName() + " " + getSurname();
}
public Person(String name, String surname, int age)
{
this.name = name;
this.surname = surname;
this.age = age;
}
/// --- STATIC METHODS --- ///
public static Person[] fetch()
{
Person[] toReturn = new Person[3];
toReturn[0] = new Person("Filip", "Ekberg", 22);
toReturn[1] = new Person("Adam", "Sandler", 99);
toReturn[2] = new Person("Jon", "Skeet", Math.Rand());
}
}