Book Image

Spring MVC Beginner's Guide

By : Amuthan Ganeshan
Book Image

Spring MVC Beginner's Guide

By: Amuthan Ganeshan

Overview of this book

Table of Contents (19 chapters)
Spring MVC Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – serving and processing forms


The Spring tag library provides some special <form> and <input> tags that are more or less similar to HTML form and input tags, but it has some special attributes to bind the form elements data with the form-backing bean. Let's create a Spring web form in our application to add new products to our product list by performing the following steps:

  1. We open our ProductRepository interface and add one more method declaration in it as follows:

    void addProduct(Product product);
  2. We then add an implementation for this method in the InMemoryProductRepository class as follows:

    public void addProduct(Product product) {
       listOfProducts.add(product);
    }
  3. We open our ProductService interface and add one more method declaration in it as follows:

    void addProduct(Product product);
  4. And, we add an implementation for this method in the ProductServiceImpl class as follows:

    public void addProduct(Product product) {
       productRepository.addProduct(product);
    }
  5. We...