I have a form that sends some data to a controller, when I send only text data it works fine, but when I send a given type number (and that in the controller I expect to receive a Double parameter) gives bad request error. If any field is sent empty, I deal with jquery to identify the empty fields in a service (if the field is not filled the jquery fills with 'null' and then my service understands that it has not been filled).
Form
<form action="/pecas/teste" id="pesquisa">
Descrição:
<input type="text" name="descricao" id="desc">
Categoria:
<input type="text" name="categoria" id="cat">
Tamanho:
<input type="text" name="categoria" id="tam">
Cor:
<input type="text" name="cor" id="cor">
Preço:
<input type="number" name="preco" id="preco">
<input type="submit">
</form>
Jquery
$("#pesquisa").submit(function(){
if($("#desc").val() == '')
$("#desc").val('null');
if($("#cat").val() == '')
$("#cat").val('null');
if($("#tam").val() == '')
$("#tam").val('null');
if($("#cor").val() == '')
$("#cor").val('null');
//como não sei o que está dando errado
//não tô fazendo o tratamento para preco
});
Controller
@RequestMapping(path="/teste")
public ModelAndView mostrarPecas(@RequestParam String descricao, @RequestParam String categoria, @RequestParam String cor,
@RequestParam String tamanho, @RequestParam Double preco) {
ModelAndView mv = new ModelAndView("verpecas");
List<Peca> pecas = service.getPecas(descricao, categoria, tamanho, cor, preco);
mv.addObject("pecas", pecas);
return mv;
}