3

Here's my Object that I've retrieved from the DB:

@RequestMapping("/category/edit/{id}")
@org.springframework.transaction.annotation.Transactional
public ModelAndView displayCategoryList(@PathVariable("id")Integer id){
    ModelAndView mav = new ModelAndView("category-form");
    List<CatFeatGroup> catFeatGroupList = catFeatGroupService.findGroupsForCategory(id);
    mav.addObject("catFeatGroupList",catFeatGroupList);
    return  mav;
}

Here's my form.

<form class="form-horizontal">
    <div th:each="catFeatGroup,status : ${catFeatGroupList}" class="form-group">
        <label>Position</label><input th:field="catFeatGroupList[${status.index}].position"  th:value="${catFeatGroup.position}" />
        <label>Name</label> <input name="catGroupList[${status.index}].name" th:value="${catFeatGroup.name}" />
    </div>
    <button type="submit" class="btn btn-default">Submit</button>
</form>

I need to use th:field to bind that object however this error shows up:

Could not parse as expression: "catFeatGroupList[${status.index}].position"

DimaSan
  • 12,264
  • 11
  • 65
  • 75
user962206
  • 15,637
  • 61
  • 177
  • 270

1 Answers1

8

Add the "__" notation like this

<form class="form-horizontal">
    <div th:each="catFeatGroup,status : ${catFeatGroupList}" class="form-group">
        <label>Position</label><input th:field="*{catFeatGroupList[__${status.index}__].position}"  th:value="${catFeatGroup.position}" />
        <label>Name</label> <input data-th-name="*{catFeatGroupList[__${status.index}__].name}" th:value="${catFeatGroup.name}" />
    </div>
    <button type="submit" class="btn btn-default">Submit</button>
</form>
Mahozad
  • 18,032
  • 13
  • 118
  • 133
KyelJmD
  • 4,682
  • 9
  • 54
  • 77