Why: The modelAttribute attribute of the form tag tells Spring which model attribute holds the object that the form is bound to.
4. What is the path attribute of tags like input and errors used for?
Why: The path attribute is the name of a property in the backing object. The tag uses it to show the property value or its validation errors.
5. Which Spring form tag displays the validation error messages of a field?
Why: The errors tag shows the validation error messages for the property given in its path attribute.
6. A form uses modelAttribute="user". What must the controller do before showing this form for the first time?
Why: The form tag looks for the form object in the model using the given name. If the object is missing, the page fails to render, so the controller must add it.
7. Which annotation connects a handler method parameter to the modelAttribute name used in the form tag?
Why:@ModelAttribute with the same name as the form's modelAttribute binds the submitted form data to the handler method parameter.
8. What does the errors tag render when a field has a validation error?
Why: The errors tag renders the error message inside an HTML span element.
9. What does the errors tag render when the field has no validation errors?
Why: If there are no errors for the given path, the errors tag does not produce any output.
10. Which attribute of the errors tag applies a CSS class to the error message?
Why: The cssClass attribute sets the CSS class of the HTML element rendered by the tag, so you can style the error messages.
11. Why are Spring form tags useful for validation compared to plain HTML form elements?
Why: Spring form tags are bound to the backing object. They show the current values and the validation errors automatically, so you do not have to copy error messages into the model yourself.
12. When using @Valid on a handler parameter, which parameter type must come right after it to receive the validation results?
Why: A BindingResult parameter placed right after the validated object holds the validation errors. Without it, Spring throws an exception when validation fails.
13. When validation fails, what does a handler method usually do so the user can see the errors?
Why: Returning the form view again shows the form with the entered values and the error messages. The errors tag then displays the messages.
14. By default, what value does the Spring password tag render when the form is shown again after a validation error?
Why: For security, the password tag does not show the entered password again by default. The field comes back empty.
15. What does the Spring input tag with path="name" render in HTML?
Why: The input tag renders an HTML text input. Its id and name come from the path, and its value comes from the backing object property.