Question

When I put the code inside the form:form tag on view cadastro.jsp:

<div class="form-group">
<label for="nome" class="col-sm-2 control-label"> name Project: </ label>
<div class="col-sm-10">
<input for="nome" class="form-control" />
<form:errors path="nome" />
</div>
</div>

Its works

but when i put

<div class="form-group">
<label for="nome" class="col-sm-2 control-label"> Nome do Projeto: </ label>
<div class="col-sm-10">
<form:input  cssClass="form-control" path="nome" />
<form:errors path="nome" />
</div>
</div>

not work because the form: input tag

Error:

HTTP Status 500 - An exception occurred processing JSP page /WEB-INF/view/cadastro.jsp at line 34

ProjetroController

@RequestMapping(value = "/novoProjeto", method = RequestMethod.POST)
public String adicionarProjeto(@Valid @ModelAttribute("projeto") Projeto projeto, BindingResult result) {
    if(result.hasErrors()) {
        return("cadastro");
    }
    projeto.setStatus("NOVO");
    this.pc.salvar(projeto);
    return "redirect:/listar";

}
Was it helpful?

Solution 2

you have to import spring form taglib inorder to use elemnets of spring form like:

add this in top of your jsp

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>

then, you can use like:

<form:form id="myForm" method="post" action="/someAction" modelAttribute="formBean">            
     <form:label path="name"/>
     <form:input path="name"/>
<form:form>

and you have add modelAttribute/command object in controller like:

@RequestMapping(value="/someUrl", method=RequestMethod.GET)
public String showForm(Model model){
   model.addAttribute("formBean", new FormBean());
   return "someViewName";
}

and FormBean class looks like:

public class FormBean {

  private String name;
  public FormBean(){} //default constructor  

  //getter and setter for name
}

OTHER TIPS

I think you need to add a <form:form> tag around your form, as follows:

 <form:form>  
 <div class="form-group">
 <label for="nome" class="col-sm-2 control-label"> Nome do Projeto: </ label>
 <div class="col-sm-10">
 <form:input  cssClass="form-control" path="nome" />
 <form:errors path="nome" />
 </div>
 </div>
 </form:form>  

In Spring official documentation, it states that:

All the other tags in this library are nested tags of the form tag.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top