Yogi
Yogi

Reputation: 1579

HTTP Status 400 The request sent by the client was syntactically incorrect

This is my controller

@RequestMapping("/offercreated")

 public String offerCreated(@Valid Offer offer, Model model, BindingResult  result) {

 if (result.hasErrors()) {

 return "createoffer";

 } else {

 System.out.println("form validated");

 return "offercreated";

 }

and my bean is

@Size(min = 5, max = 45)
    private String name;

The form is validated when i give the name of between 5 and 45 characters. But when the form is not validated I am getting 400 status error report. I dont know why i am getting the error. Please need help here

Upvotes: 0

Views: 348

Answers (2)

Ardavel
Ardavel

Reputation: 1515

BindingResult parameter must follow the parameter being validated immediately. It's described here: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html

org.springframework.validation.Errors / org.springframework.validation.BindingResult validation results for a preceding command or form object (the immediately preceding method argument).

Upvotes: 1

Yogi
Yogi

Reputation: 1579

Wow when i change the controller parameters to Model and then Offer its working !!

@RequestMapping("/offercreated")

public String offerCreated(Model model, @Valid Offer offer, BindingResult result) {

if (result.hasErrors()) {

return "createoffer";

} else {

System.out.println("form validated");

return "offercreated";

}

can someone explain why that is ? i am so confused !

Upvotes: 0

Related Questions