1

I have a nested each structure that loops through a tree. Html code is as follows:

<div th:each="group : ${groups}" class="row corp-teams-group-row">
    <h2 th:text="'- ' + ${group.name}">GROUP NAME</h2>
    <div th:each="team : ${group.teams}" class="row corp-teams-teams-row">
        <h2 th:text="'- ' + ${team.name}">TEAM NAME</h2>
        <div class="col-xs-6 corp-man-wrapper corp-admin-wrapper">
            <div class="corp-user-image-container">
                <div class="corp-user-image-wrapper">
                    <img th:src="${team.users[0].image}">
                </div>
                <div class="corp-bugcount"><span th:text="${team.users[0].score}"></span></div>
            </div>
            <div class="corp-user-data-container">
                <h2 th:text="${team.users[0].name} + ' ' + ${team.users[0].surname}"></h2>
                <div class="corp-user-email" th:text="${team.users[0].email}"></div>
            </div>
        </div>
        <div class="col-xs-6 corp-man-wrapper">
            <h3 th:text="${team.newFeatureCount}"></h3>
            <h3 th:text="${team.defectCount}"></h3>
        </div>
        <div th:each="user : ${team.users}" class="col-xs-6 corp-man-wrapper">
            <div class="corp-user-image-container">
                <div class="corp-user-image-wrapper">
                    <img th:src="${user.image}">
                </div>
                <div class="corp-bugcount"><span th:text="${user.score}"></span></div>
            </div>
            <div class="corp-user-data-container">
                <h2 th:text="${user.name} + ' ' + ${user.surname}"></h2>
                <div class="corp-user-email" th:text="${user.email}"></div>
            </div>
        </div>
    </div>
</div>

The admin user is 0th index of each user array. But the notation to reach it obviously fails. I can confirm that the back-end data is correct. I get this error when this code runs on the server:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "team.users[0].score" (teams)

I can't figure out what is wrong with this code and no similar examples on the net that cracks this problem. Thanks.

5
  • 1
    What's the root cause? The "Exception evaluating SpringEL expression" is just the outermost exception. Look at the last one to see the cause. Commented Nov 14, 2016 at 13:27
  • Yes it has a third caused by at the bottom and it says "org.springframework.expression.spel.SpelEvaluationException: EL1025E:(pos 10): The collection has '0' elements, index '0' is invalid" Commented Nov 14, 2016 at 13:32
  • 1
    Well, there's your problem. Commented Nov 14, 2016 at 13:34
  • Then this is your answer ;-) Then add an th:if if it this case could occur Commented Nov 14, 2016 at 13:34
  • You can write this as a solution and I'll accept as an answer thanks. Commented Nov 14, 2016 at 13:34

1 Answer 1

1

As mentioned in the comments: the cause of the exception is

"org.springframework.expression.spel.SpelEvaluationException‌​: EL1025E:(pos 10): The collection has '0' elements, index '0' is invalid"

Simply add an th:if condition if the team.users can have zero elements.

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

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.