Personal, there is a boring error in which I'm losing sleep to find out how to treat.
Well, every time I run my test by checking the validation of my field a 400 error is triggered.
I do not know how I can resolve this. The server log does not report anything.
below the HTML:
<div class="body-nest" id="basic">
<div class="form_center">
<c:if test="${validator}">
<div class="alert alert-danger">
<button data-dismiss="alert" class="close" type="button">×</button>
<span class="entypo-attention"></span> <strong>Opa!</strong> Você
não pode deixar o campo abaixo em branco e ele tem que ter mais
que três caracters!.
</div>
</c:if>
<f:form action="updateCategory" method="get" modelAttribute="categoryModify">
<input type="hidden" name="id" value="${categoryModify.idCategory}"/>
<div class="form-group">
<f:input type="text"
id="inputCategory" class="form-control" path="ctName" value="${categoryModify.ctName}"/>
</div>
<f:button class="btn btn-info" type="submit">Alterar</f:button>
<a class="btn btn-default" href="<c:url value="category"/>">Cancelar</a>
</f:form>
</div>
</div>
The controller:
//Mapeamento para mostrar a categoria na tela.
@RequestMapping(value="editCategory", method = RequestMethod.GET)
public String editCategory(Long id, Model model, @Valid Category category, BindingResult result){
model.addAttribute("validator", false);
model.addAttribute("categoryModify", dashboardFacade.getCategoryId(id));
return "category/updateCategory";
}
// Update da categoria
@RequestMapping(value="/updateCategory", method = RequestMethod.GET)
public String updateCategory( @Valid Category category, @RequestParam Long id, @RequestParam String ctName, BindingResult result, Model model) {
if (result.hasErrors()) {
model.addAttribute("validator", true);
return "category/updateCategory";
} else {
dashboardFacade.categoryUpdate(ctName, id);
logger.info("A categoria " + category.getIdCategory() + " pertencente a agência " + dashboardFacade.getAgency() + " foi adicionada.");
return "redirect:category";
}
}
Template:
@Column(name="ct_name")
@NotEmpty
private String ctName;
Thank you all!