Thank you for your help. And sorry because I didn't explain my issue very well.
I am using an ArrayList for the movies so I need to specify an index on the html page, but I don't know how to do it, because it doesn't work.
Really, my case is a little bit more complex. I have the next method for create the form:
@RequestMapping(value = "/formadd", method = RequestMethod.GET)
public String addForm(Model m1, Model m2) {
m1.addAttribute("catalogo", new Catalogo());
m2.addAttribute("peliculas", new ArrayList<Pelicula>());
return "formadd";
}
I want to create a movies catalog, so in the html I have two forms, one for create the catalog and another for add a list of movies to the current catalog. I think that the catalog form works ok (I can't be sure yet because to submit the catalog form I have to submit before the movies form because is not possible to have a catalog without movies).
In peliculaService I have the method "insertarCatalog" where I insert a new catalog (I need the catalog's id for the movies) and the in a for I iterate and add the movies to the catalog.
In the controller, when I click on submit, I have the next method:
@RequestMapping(value = "/submitcatalog", method = RequestMethod.POST)
public String addCatalog(@ModelAttribute("catalogo") Catalogo c, @ModelAttribute("peliculas") List<Pelicula> pelis)
throws InstantiationException {
peliculaService.insertarCatalogo(c, pelis);
return "submit";
}
Here is the form to create a catalog:
<form th:action="@{/submitcatalog}" th:object="${catalogo}" method="post">
<tr>
<td><label th:text="#{nombre}">Nombre: </label></td>
<td><input type="text" th:field="*{nombre}" /></td>
</tr>
<td>
<input type="submit" value="Aceptar">
</td>
</form>
I want to click on a "add" button on the movies form in order to add this movie to the catalog. So when I press this button, I can to add another movie, and when I finish to add movies to the catalog, I have to press "submit" on the catalog form to insert all the data on the database (the catalog's id is generated by hibernate, and the movie's id is generated by me on the service).
I hope you can understand me, and thank you so much!