Chapter 5. Using Forms

In this chapter, we will cover the following recipes:

  • Displaying and processing a form
  • Getting a submitted form value using a controller method argument
  • Setting a form's default values using a model object
  • Saving form data in an object automatically
  • Using text, textarea, password, and hidden fields
  • Using a select field
  • Using a checkbox
  • Using a list of checkboxes
  • Using a list of radio buttons
  • Validating a form using annotations
  • Uploading a file

Introduction

Displaying and processing a form is tedious. Spring helps with the initialization of the form, the generation of form widgets (text fields, checkboxes, and so on), and data retrieval when the form is submitted. Form validation is made simple with annotations in the model classes.

Get Spring Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.