aspose file tools*
The moose likes Struts and the fly likes Struts 2 iterators Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 iterators" Watch "Struts 2 iterators" New topic
Author

Struts 2 iterators

anna lanzaro
Greenhorn

Joined: Nov 24, 2009
Posts: 8
Hi,
I have a problem with iterator. I have a class SearchStudent that send a query to db that return List<Student> students.
In the jsp I want display the name and the age of the students.

I wrote:
<s:iterator value="students" id="next" >
<s:property value="#next.name"/>
</s:iterator>
in the jsp page i can't see nothing but if I change in
<s:iterator value="students" >
<s:property "/>
i can see only the id of the first student (that is the first field in the db)

how i can display correctly the students???
Please, Help me!!!
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276


Inside the iterator tag, the current object will be on the top of the value stack and with value="name" you will retrieve its name attribute...


OCJP 6 (93%)
anna lanzaro
Greenhorn

Joined: Nov 24, 2009
Posts: 8
I wrote:


but i can't see nothing in the jsp page.

I try to explain better my application.
I send a query to my db (SELECT name,age from Student) that return: List<Student> students.
Student is a class with attribute: id, name, age, address.
So if I wrote



I can see in the jsp page 3 name of 3 student.
Instead if i wrote:

I can't see nothing!!!

Any suggestion???
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
Does Student have public name and age fields or getters (getName(), getAge())..?
anna lanzaro
Greenhorn

Joined: Nov 24, 2009
Posts: 8
Yes Student have getName,setName etc...

(the query is implemented in a class named SearchStudent that have attribute: List<Student> with get and set method)
anna lanzaro
Greenhorn

Joined: Nov 24, 2009
Posts: 8
Lorand Komaromi wrote:Does Student have public name and age fields or getters (getName(), getAge())..?


excuse me but student extends user so student don't have name and age fields or getters but user have these public fields/getters!!!

 
Don't get me started about those stupid light bulbs.
 
subject: Struts 2 iterators
 
Similar Threads
iterate list issue...
Need to create dynamic <s:property tag using <s:iterator
Sticky nested lists problem in Struts 2
Struts2 iterator
Struts2 Iterator