0

I need an explanation on the role of BindingResults. Though i have studied it on internet and it seem to be used for validating the request and holding errors but i haven't found answers in details that could explain the situation i experienced.

So below is a field in an Entity

private List<Grade> listOfGrade;

which is populated from a form

Select Grades

    <td>   
           <select id="listOfGrade" name="listOfGrade" multiple="multiple">
             <option value="70">6</option><option value="71">7</option><option value="72">8</option><option value="73">9</option><option value="74">9</option>
           </select><input type="hidden" name="_listOfGrade" value="1"/>
   </td> 
</tr>

If i remove the above mentioned "select" from the form, the form gets submitted without bindingResult; but if kept the form does not get submitted without BindingResult option being added to controller method. It gives error 400. Why?

Thanks in Advance! Abhi

Abhi0008
  • 1
  • 2

1 Answers1

0

The answer for you question regarding the 400 Bad request error is if you remove the select then obviously it will give the 400 error because the listOfGrade field will not be present.

and to validate list please refer below answer.

https://stackoverflow.com/a/34227850/6572971

Hope it helps.

Alien
  • 15,141
  • 6
  • 37
  • 57
  • So removing the select worked fine but it was giving 400 otherwise. What i understand is that whenever there are custom attributes associated with the beans then we need to have BindingResult object ....otherwise framework throws exception asking for it...if this understanding is correct then pls close the ticket. – Abhi0008 Jan 11 '19 at 08:55