-1

I am binding a list to field from thymleaf view, but getting null in the controller. Consider it is not null in view.

<form th:object="${obj}"
  <input type="hidden" th:field="*{someList}" th:value="${obj.getSomeList()}">

POJO is like this:

public class Foo {
  private int id;
  private List<Some> someList;

  //setter getter

}

If I bind the id in same way I am getting it in controller, pls help If I have take special care for List.

My controller:

@RequestMapping
public String bar(@ModelAttribute("obj") Foo foo)
Anil Bhaskar
  • 3,718
  • 4
  • 33
  • 51

1 Answers1

1

Hi Anil after setting the values to a variable you need to iterate through the list using the each tag Pls find the syntax

<form th:object="${obj}" th:action="@{/list}" action="void(0)" method="post">
    <tr>    
        <td th:field="*{id}" th:text="${obj.id}" /> 
    </tr>
    <tr th:each="l , i : ${obj.someList}">
        <input type="hidden" th:field="*{someList[__${i.index}__].something}" />
    </tr>
    <input type="submit" class="btn btn-success" />
</form>
Anil Bhaskar
  • 3,718
  • 4
  • 33
  • 51
Pradeep
  • 1,947
  • 3
  • 22
  • 45