I have this class Dog.java and a List<Dog> that is passed to dogs.jsp page.
public class Dog {
public String name;
public String breed;
public Dog(String name, String breed) {
this.name = name;
this.breed = breed;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBreed() {
return breed;
}
public void setBreed(String breed) {
this.breed = breed;
}
}
I try to display each dog, but although it does loop over all dogs in the list (displays table headers 5 times), it doesn't display the dogs names and breeds. Why?
<s:iterator value="dogs" status="x">
<table>
<tr>
<th>Name</th>
<th>Breed</th>
</tr>
<tr>
<td><s:property value="%{#x.name}"></s:property></td>
<td><s:property value="%{#x.breed}"></s:property></td>
</tr>
</table>
<br/><br/>
</s:iterator>
statusis for status, not each item in the iteration. You need to either use thevarproperty, or just skip it and use%{name}etc. since the item of iteration is at the top of the value stack. Note that this information is contained in the documentation.