vendredi 10 avril 2015

selector thymeleaf spring

I try do a selector in thymeleaf and spring, but i dont know because i recibe error.


I have this code:



@RequestMapping(value="/", method=RequestMethod.GET)
public String showForm(Person person, Model model) {

List<Person> list = new ArrayList<Person>();
Person p1 = new Person();
p1.setName("John");
p1.setAge(46);
Person p2 = new Person();
p2.setName("Helen");
p2.setAge(34);
list.add(p1);
list.add(p2);
model.addAttribute("list",list);
return "form";
}


and the html is this:



<html>
<body>
<form action="#" th:action="@{/}" th:object="${person}" method="post">
<table>
<tr>
<td>Name:</td>
<td><input type="text" th:field="*{name}" /></td>
<td th:if="${#fields.hasErrors('name')}" th:errors="*{name}">Name Error</td>
</tr>
<tr>
<td>Age:</td>
<td><input type="text" th:field="*{age}" /></td>
<td th:if="${#fields.hasErrors('age')}" th:errors="*{age}">Name Error</td>
</tr>
<tr>
<select id="person" th:field="*{person}">
<option th:each="p : ${list}" th:value="${p.getName()}" th:text="${p.getName()}"></option>
</select>
<td><button type="submit">Submit</button></td>
</tr>
</table>
</form>
</body>


I execute, but i recibe this error:



There was an unexpected error (type=Internal Server Error, status=500).
Error during execution of processor 'org.thymeleaf.spring4.processor.attr.SpringSelectFieldAttrProcessor' (form:16)


What is the problem??


One answer more, when user select person in selector, how i catch this name for use in the java code?


Thank you very much!


Aucun commentaire:

Enregistrer un commentaire