Not to be confused with this question!
So, I'm trying to pass a bean in a Thymeleaf fragment and to bind its properties to some fields.
I.e. Let's say I have a fragment called myFragment:
<div th:fragment="myFragment(myBean)"> <select class="selectpicker" th:field="${myBean.myProperty}"> <option th:each="myProperty : ${myBean.myProperties}" th:value="${myProperty}" th:text="${myProperty}"></option> </select> </div> And fragment is being called like this:
<div th:include="fragments/myFragment:: myFragment(myBean=${myBean})"> ... </div> And that works for some reason because the name of the variable and the name of the bean are the same (myBean). But if the name of the bean is different, i.e. like this:
<div th:include="fragments/myFragment:: myFragment(myBean=${someOtherBean})"> ... </div> I get an exception:
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'myBean' available as a request attribute Everything works fine for other attributes like th:text, th:href... However, the exception occurs if I use th:field attribute (if I try to bind a property to some specific field). How to properly perform binding in this case?
<div th:include="fragments/init :: pagination (page=${listPage})"></div>