Rookie question here, I have an <input> that I'd like to display a User's nested property using Thymeleaf
- Each User has a Department
- Every Department has a name
I attempt to access it like by sending a List of User objects to my form
<select id="user">
<option value="" th:text="-Select-"></option>
<option
th:each="user: ${users}"
th:value="${user.id}"
th:text="${user.name}"
th:attr="data-department=${user.department.name}">
</option>
</select>
Thymeleaf can locate the nested department object (returns [object, Object]), but when trying to access the department name a SpringExpressionLanguage Exception when trying to access the name of the department.
org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Property or field 'name' cannot be found on null
I'm still going through the documentation, but haven't found how to access this yet which is probably extremely simple. Any ideas?
departmentclass. could you provide the code of it?