I am trying to use the struts iterator to write some data from a List. Student is a class I have defined.
The s:property when used with the value attribute does not seem to work at all.
I have the following code in the JSP:
<s:iterator value="students" var="student">
<h2><s:property /></h2>
<h2><s:property value="firstName" /></h2>
<h2><s:property value="student.firstName" /></h2>
<h2><s:property value="top.firstName" /></h2>
<h2><s:property value="[0].firstName" /></h2>
<h2><s:property value="#firstName" /></h2>
</s:iterator>
On the first property tag works. It prints the toString() of the Student object. All other property tags do not print anything at all.
The toString() method of Student class is as follows:
public String toString() {
return firstName + " " + lastName + " " + Integer.valueOf(age);
}
The Student class has the getFirstName() method as follows:
String getFirstName() {
return firstName;
}
I am using Struts 2.1.6
There are no exceptions in the log files.
When viewing source of html, I just see the empty h2 tags.
I wonder what is the issue here. Any help is appreciated.
Your getFirstName() method only has package-level access. It should be public to be accessible from the JSP.
change it to
public String getFirstName()and you’re set.