Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3345522
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:11:45+00:00 2026-05-18T01:11:45+00:00

New to Spring here, and after reading the reference docs the workflow to validate

  • 0

New to Spring here, and after reading the reference docs the workflow to validate a simple web form isn’t popping out at me.

Could someone give me a beginners overview of how we go about form validation in Spring 3.0.3 (I’m using a mix of annotations and xml config in a webapp that I’m migrating now). Starting from the Controller, what happens?

For example: so far I think I understand that I should “bind” the form data to an object of my creation (say MyPerson for example), then create a Validation object that accepts MyPerson and uses ValidationUtils to perform the validation.

But that’s all very fuzzy in my head (especially the “binding” concept) and a step by step review of the workflow from someone who’s been through it before would help me be confident that I’m not missing or mis-interpreting any steps.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:11:46+00:00Added an answer on May 18, 2026 at 1:11 am

    The method you are mentioning for validating forms is one of a few options you have available.

    As well as the method you have suggested you may also want to investigate using JSR-303 annotations with an appropriate implementation (for example Hibernate Validator). There are a lot of example of how to accomplish this.

    For the spring validation method your basic steps are:

    • Create an class to act as a binding object, pass an instance of this to the view in your controller
    • Bind the object to the fields in your view using the form taglib
    • In the controller method which handles the form submission, use the @ModelAttribute annotation to bind the form data to your binding object
    • Use your custom validator object (probably @Autowired to your controller) to perform validation

    Heres a simple example controller:

    @Controller
    public class PersonController {

    @Autowired
    private PersonValidator personValidator;
    
    @RequestMapping(value="person/form", method = RequestMethod.GET)
    public ModelAndView form() {
        // Instance of binding object
        Person person = new Person();
    
        // Create ModelAndView which displays personForm view
        ModelAndView mav = new ModelAndView("person/form");
        // Put our binding object in the model
        mav.getModel().put("person", person);
    
        return mav;
    }
    
    @RequestMapping(value="person/form", method = RequestMethod.POST)
    public String save(@ModelAttribute Person person, BindingResult errors, Model model) {
        // Call our custom validator and put errors into BindingResult
        personValidator.validate(person, errors);
    
        // If we have validation errors
        if (errors.hasErrors()) {
            // Show form with errors
            return "person/form";
        }
    
        // Otherwise show some success page
        return "person/success";
     }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

after reading the Zend documentation and some posts here I could not figure out
After searching the web and reading docs on MSDN, I couldn't find any examples
I'm new to spring controllers using annotated controllers. Here is my configuration Bean definition
Here is a simple sorting program of an ArrayList: ArrayList<String> list = new ArrayList<String>();
I am new to Spring MVC . I have a web application. I have
After reading this question here: Passing one Dimension of a Two Dimensional Array in
I'm new with Java NIO, after reading some tutorials, I've tried my own to
here's the method: public static int chooseStrat () { String[] strats = new String[1]
String[] a = c.toArray(new String[0]); First: Do I need type cast here? (I think
Here is my code: new Loading.LoadTast(ctx) { @Override protected String doInBackground(Integer... params) { Looper.prepare();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.