Here, I am iterating a list using th:each. Initially, the parentCategory variable is empty and if condition evaluates to true and the parentCategory value is changed to name. But for the next iteration, instead of keeping the value of parentCategory unchanged, it is being changed to initial value that is empty/' ' and hence if condition evaluates to true each time.
Is this due to the scope of the variable? Does anyone has any idea about this?