Save a jsp form

Asked

Viewed 99 times

1

When you save a form, that is, you go to the Spring Controlle class, I need the same to make 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>

In the Controlle it’s 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 saving and sending the error message correctly, it clears the other fields.

What would be the best way ?

  • Your only need is to make certain field of your form mandatory?

  • @R.Santos you’re talking about this required tag=", within imput ?

  • Depends on what you need, if your only need was to make the field mandatory I would suggest it to you

  • I didn’t want to. But anyway, I need to change the controller’s return. For example, I have to make a query and validate if the information already exists in the database.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.