5

I've tried searching for existing answers, but I could not find them.

I'd like to access an ArrayList from an object within an ArrayList, so:

Basically two classes: Glossary and Word. Glossary contains a list with Word objects, the class Word contains a list with more Word objects (related words)

<table>
<span th:each="word : ${glossary.words}">
 <td>
  <tr th:each="relatedWord: ${word.relatedWords}">
    <p th:text="${relatedWord.getName()}"></p>
  </tr>
 <td>
</span>
</table>

Unfortunately this does not work for me..

1
  • What output do you get? Commented Nov 13, 2013 at 15:01

2 Answers 2

14

I'm not sure but I don't think you can access public non-static getters like you do (assuming getName() is marked as public).

You should try:

<table>
    <span th:each="word : ${glossary.words}">
        <td>
            <tr th:each="relatedWord: ${word.relatedWords}">
                <p th:text="${relatedWord.name}"></p>
            </tr>
        <td>
    </span>
</table>

One note: the above code is absolutely not valid XHTML (span directly inside table, tr directly inside td).

Sign up to request clarification or add additional context in comments.

3 Comments

No..yes you are right, about the markup. The actual code is not like that, probably made a mistake when creating this 'more readable', yet identical piece of code.
You could use <th:block /> instead of <span/>, to make it a valid XHTML
this comment should be an answer
0

I've trying to figure out this too. Using Spring Boot back-end.

I have a class App with a @ManyToOne relationship with Cube.

I'm trying to produce a table where each record represents an App and within one of the cells would list out the related Cube objects.

<tr th:each="app : ${apps}">
  <td th:text="${app.id}">ID</td>
  <td th:text="${app.name}">Name</td>
  <td th:text="${app.description}">Description</td>
  <td th:text="${app.url}">URL</td>
  <td>
    <ul>
      <li th:each="cube : ${app.cubes}">
        <span th:text="${cube.name}">Name</span>
      </li>
    </ul>
  </td>
</tr>

I currently have 3 Apps in the database, each with 3-4 related Cubes.

The App rows are generating correctly, but the I am only getting a single Cube item listed. As it happens, the id of both objects is 1 I noticed.

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.