In this post, we will see how to resolve Thymeleaf iteration status variable is null
Question:
This is my data class survey nothing unusual here I even have eager loading to prevent issuesEL1021E: A problem occurred whilst attempting to access the property 'last': 'Unable to access property 'last' through getter method'
Unable to access property 'last' through getter method
Cannot invoke "java.lang.Integer.intValue()" because "this.size" is null
I’m not sure why when i use surveyStat.odd there is no issue but when I use surveyStat.last I’m given an error and the index page is no longer able to load
There is no issue on compilation but rather when the view index is attempting to load the error EL1021E shown below is thrown.
Best Answer:
Page<T>
(provided your surveyRepository
is a default PagingAndSortingRepository)This
Page
neither implements Collection
nor Map
and it isn’t an array. So thymeleaf will compute the size as null
. You can check the relevant code here.What you could do is instead of passing the
Page
to the model pass a Collection
instead:If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com