How to pass /update javascript object (list) in thymeleaf

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to pass /update javascript object (list) in thymeleaf

trymafat@yahoo.com
Am using Thymeleaf 2.x with spring-boot 1.5.x application.

I have below code fragment that loops thru result set in a div. What I want to do is to update the div (the list object that is being iterated over i.e. ${sObjWithStuff.listResults}) based on user actions.

...
 <div class="row" id="outerDivloop"  th:each= "cntr, rStats: ${sObjWithStuff.listResults}"> 
          <div class="row form-group ag-abs-pos-children"> 
            <label for="ID" class="col-form-label">ID</label>
            <input type="text" class="form-control" name="ID" th:value="${cntr.id.recordId}" style="width: 10em"/>
...

Controller fills the object "sObjWithStuff" with lot of stuff in addition to a List-of-objects (PoJo) in "listResults"

When the page loads  ${sObjWithStuff.listResults} has, say 10 records, now using some input controls I want to dynamically update the page without going back to the server.

What I am trying to do is, filter results based on input control being updated.
Conceptually like : https://datatables.net/examples/styling/bootstrap4.

I have used javascript to read the list ${sObjWithStuff.listResults} in a inline script tag and might be able to filter the records based on parameters passed.

I just do NOT know how to update the ${sObjWithStuff.listResults} .

Basically how can I refer a variable defined in script tag in thymeleaf attribute.

This shows how to pass object from Thymeleaf to JS, but I need the opposite.

Please help.