When you save a form, that is, it goes to the Spring control class, I need it to throw an exception, to warn the user that some field is required.
In JSP it looks like this:
<c:if test="${not empty param.e}">
<div class="form-group has-error">
<label for="inputError" class="col-xs-12 col-sm-3 col-md-3 control-label no-padding-right">
<i class="ace-icon fa fa-times-circle"></i> Campos com * são obrigatórios !</label>
</div>
</c:if>
Do not control it like this:
@RequestMapping("salvarPais")
@Transactional
public String cadastrar(PaisEntity pais, Model model) {
if (pais.getDescricao() == null || pais.getDescricao().isEmpty()) {
model.addAttribute("e", "e");
return "redirect:novoPais";
}
String pagina = "";
if (pais.getId() == null) {
pagina = "redirect:novoPais/?i=ok";
} else {
pagina = "redirect:editarPais?id=" + pais.getId() + "&a=ok";
}
repository.salvar(pais);
return pagina;
}
The problem is that when you save and emit the error message correctly, it clears the other fields.
What would be the best way?