0
Guys, there’s a boring mistake that I’m losing sleep over to figure out how to treat.
Well, every time I perform my test by checking the validation of my field an error 400 and fired.
I don’t know but how do I resolve this issue. The server log shows nothing.
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";
}
}
Model:
@Column(name="ct_name")
@NotEmpty
private String ctName;
Thank you all!
Buddy, this code of yours is a little confusing. Actually doing what you’re looking for is easier than you think. Take a look at these links: Forms, A practical example. Success! :)
– Fábio Zoz
Hi Fabio, actually it was my own mistake. Cool the links you sent. It will clarify me many doubts from now on.
– João Manolo