How to map complex structure in jsp view to model object in spring MVC

I am using spring mvc for the first time and I am trying to display and edit the structure in jsp.

I have a Snippet class that contains a list of objects of type Sentence:

public class Snippet {
  private int id;
  private List<Sentence> sentences;
  // getters, setters, default constructor
}

public class Sentence {
  private int id;
  private int scale;
  private String text;
  // getters, setters, default constructor
}

In my controller, I give a new snippet for editing, and when the user clicks "Save", save it in my db, and then return another one. Currently, the list of sentences for the fragment is null:

@RequestMapping("/snippet")
public ModelAndView getSnippet() {
  return new ModelAndView("snippet", "snippet", snippetService.getSnippet());
}

@RequestMapping("/save")
public ModelAndView saveSnippet(@ModelAttribute Snippet snippet) {
  if(snippet != null && snippet.getSentences() != null && !snippet.getSentences().isEmpty()) {
    snippetService.updateSnippet(snippet);
  }
  return new ModelAndView("snippet", "snippet", snippetService.getSnippet());
}

In my snippet.jsp, I would like to display fragment sentences with their scale and save, transfer the fragment with sentences and scales for the controller for storage:

<form:form method="post" action="save" modelAttribute="snippet">
  ...
  <c:forEach var="sentence" items="${snippet.sentences}">
    <tr>
      <td>${sentence.id}</td>
      <td>${sentence.text}</td>
      <td><input type="range" name="sentence.scale" value="${sentence.scale}"
         path="sentence.scale" min="0" max="5" /></td>
    </tr>
  </c:forEach>
  <tr>
    <td colspan="4"><input type="submit" value="Save" /></td>
  </tr>

I think I need to find the correct way to use the path attribute, but I cannot figure it out.

+4
1

JSTL c:forEach varStatus, . index of varStatus, , , .

<c:forEach var="sentence" items="${snippet.sentences}" varStatus="i">
    <tr>
      <td>${sentence.id}</td>
      <td>${sentence.text}</td>
      <td>
        <form:input type="range" 
          name="snippet.sentences[${i.index}].scale" 
          path="sentences[${i.index}].scale" 
          min="0" max="5" 
          /></td>
    </tr>
  </c:forEach>
+2