Hi
I am having an action class where I return an object list of users(like name,email,etc) fetched from DB.
using <s:iterator> tag in struts2, how can i display the table data in jsp.
Thanks in advance
Hi Rajani,
I am going to explain it with an example. Hope this will clear your doubt.
First create an simple POJO, for example let us call it Employee. Let the Employee object hold the name, email, and age. You employee class will look like this
In the DAO implementation you can write a method like this (I am just writing an outline)
Now in the action class, make a form attribute of type List<Employee> (let us call it myEmpList) . Make its corresponding getter and setter method. After this you can call the getEmployeeList() method to get the list of employees and set it to myEmpList. So now myEmpList holds employee objects you populated from database.
Now in the jsp, we are going to make a table containing employee objects in different rows using s:iterator like this
Hello,
Thank you for the explanation.
I followed the steps above but I am able to display only the last record from the myEmpList.
Why is this behaviour any ideas?
* Is your DAO class fetching the values properly from the database?
* Iterate myEmpList in your action class and print the contents? Is it printing all the values as you expected?
When I iterate over the emplist, an object like Employee@1f30035 is printed.
In getEmployees() method of DAO class, the following is the way i add the employee objects
Employee e = new Employee();
while(rs.next()){
e.setEmployeeId(rs.getString(1));
e.setName(rs.getString(2));
e.setProject(rs.getString(3));
empList.add(e);
}
I have three rows in my table, and only the last record in the table is printed in jsp three times.
Do I have iterate over the list in iterator tag using soem index.
How do I have to write the OGNL expresion in iterator tag?
Thank you for your prompt answers.
I would like to add pagination to my results that are being displayed in jsps.
in struts2, do I get any tag that serves this purpose.