Spring MVC - Form Validation with External Messages MCQ
0/13
0✓
0✗
1. What is the main benefit of keeping validation messages in an external properties file?
Why: External messages are kept outside the Java classes. You can edit, review or translate them in one place without touching the code.
2. Which annotation correctly uses a message key from an external file?
Why: A message key is placed inside curly braces, like {product.name.size}. Without the braces, the text is shown as a plain message.
3. What do the curly braces mean in a constraint message such as "{order.quantity.min}"?
Why: Text inside curly braces is treated as a key. The real message is found by looking up that key in the external messages file.
4. What is the default base file name that Jakarta Bean Validation looks for to load custom validation messages?
Why: By default, Bean Validation looks for a resource bundle named ValidationMessages on the classpath.
5. Where should the validation messages properties file be placed in a Maven project so it can be found?
Why: The messages file is loaded from the classpath. In a Maven project, src/main/resources is copied to the classpath.
6. Which entry is written in the correct properties file format to define the message for a key?
Why: A properties file uses the simple format key=value. The key is written without curly braces in the file.
7. A file is named ValidationMessages_fr.properties. What does the _fr part mean?
Why: The suffix is a locale code. Using different files per locale lets you show validation messages in different languages.
8. Which Spring class can be registered as a MessageSource to load messages from properties files by base name?
Why:ResourceBundleMessageSource is a Spring MessageSource implementation that reads messages from resource bundles (properties files) using base names.
9. What is a basename when configuring a ResourceBundleMessageSource?
Why: For files like ValidationMessages_en.properties, the basename is ValidationMessages. Spring adds the locale suffix and extension when it loads the files.
10. Which annotation on a handler method parameter tells Spring MVC to validate the form object?
Why:@Valid triggers Bean Validation on the annotated object before the handler method runs.
11. What does the BindingResult object hold in a form handler method?
Why:BindingResult keeps the results of data binding and validation, including any field errors and their messages.
12. What is the usual thing to do in a handler method when bindingResult.hasErrors() returns true?
Why: When there are errors, the handler normally returns to the form view. The user then sees the error messages and can correct the input.
13. Which Spring form tag library tag is used to display validation error messages for a field?
Why: The errors tag from the Spring form tag library shows the error messages for a given field path.
14. A field has two constraint annotations and both fail. What is the result?
Why: Each failed constraint creates its own error. A field can therefore have more than one error message.
15. Which entry in a messages file defines the message for this annotation?