vendredi 13 mars 2015

Thymeleaf error not displayed Spring 4.x

I'm actually following the Spring validation tutorial and I can make it work properly except for one thing.


In fact, tlhe redirections/template return work great if I validate or don't validate the rules.


The thing is that I don't even see the error message in my template. I don't know what's going wrong, I use the same code than the tutorial but it doesn't display anything (the template is well rendered).


Could you help me ?


The controller :



@RequestMapping(value = "/print", method = RequestMethod.POST)
public String printPost(@Valid PrinterEntity printerentity, BindingResult bindingResult, Model model) {
model.addAttribute("printed", printerentity.getName());
model.addAttribute("printerentity", new PrinterEntity());

if (bindingResult.hasErrors()) {
return "index";
}

return "printer/secretarea";
}


The template view (index) :



<form method="post" th:action="@{/print}" th:object="${printerentity}">

<table>
<tr>
<td>
<input type="text" th:field="*{name}"/>
</td>
<td th:if="${#fields.hasErrors('name')}" th:errors="*{name}">
Name Error
</td>
</tr>
<tr>
<td>
<button type="submit">Valider</button>
</td>
</tr>
</table>

</form>

Aucun commentaire:

Enregistrer un commentaire