I'm using POI to generate the Excel spreadsheet from my managed bean. Here's my Student Bean:
package edu.phc.students.model;
public class Student {
private String m_firstName;
private String m_lastName;
private String m_id;
public Student() {}
public Student(
String firstName,
String lastName,
String id,
)
{
m_firstName=firstName;
m_lastName=lastName;
m_id=id;
}
public String getid() {
return m_id;
}
public void setid(String newid) {
m_id=newid;
}
public String getFirstname() {
return m_firstName;
}
public void setFirstname(String newFirstName) {
m_firstName=newFirstName;
}
public String getLastname() {
return m_lastName;
}
public void setLastname(String newLastname) {
m_lastName=newLastname;
}
}
This is a small segment of the final code (SSJS).
var students:java.util.List = studentlist.getStudents();
var iterator:java.util.Iterator = students.iterator();
var count = 0;
while (iterator.hasNext()) {
var student:edu.phc.students.model.Student = iterator.next();
count++;
var row:HSSFRow = sheet1.createRow(count);
for( f = 0 ; f <= fieldList.length-1 ; f++){//column List
// output student's data into Excel row
row.createCell((java.lang.Integer)(f)).setCellValue(student.getid());
}
}
This works perfectly. It generates the spreadsheet with the column names and inserts the student ID into each cell (for each row returned by the iterator).
However, I want to iterate through the properties available for the student bean - ID, Lastname, Firstname etc. and populate the cells of the spreadsheet. How do I do that? Can I reference the properties of the student bean by index?
Thanks,
Dan