0

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>
1
  • 1
    status is for status, not each item in the iteration. You need to either use the var property, 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. Commented Aug 20, 2021 at 13:50

2 Answers 2

1
<s:iterator value="dogs" var="dog">
  ...  <s:property value="#dog.name" />
 </s:iterator>
Sign up to request clarification or add additional context in comments.

Comments

0

This worked for me:

<s:iterator value="dogs" status="x">
    <br/>
    <table>
        <tr>
            <th>Name</th>
            <th>Breed</th>
        </tr>

        <tr>
            <td><s:property value="%{name}"></s:property></td>
            <td><s:property value="%{breed}"></s:property></td>
        </tr>
    </table>
</s:iterator>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.