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 8168725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:37:22+00:00 2026-06-06T20:37:22+00:00

I’m validating a form using the Validator interface with Spring MVC 3.0.2 using SimpleFormController

  • 0

I’m validating a form using the Validator interface with Spring MVC 3.0.2 using SimpleFormController. The following is the controller class which extends SimpleFormController.

@SuppressWarnings("deprecation")
final public class Temp extends SimpleFormController
{        
    public Temp()
    {
        setCommandClass(ValidationForm.class);
        setCommandName("validationForm");
    }

    @Override
    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception
    {
        ValidationBean validationBean=(ValidationBean) command;
        ModelAndView mv=new ModelAndView("Temp", "validationForm", validationBean);
        if(errors.hasErrors())
        {
            System.out.println("error");
        }
        else
        {
            System.out.println("name = "+validationBean.getUserName());
        }
        return mv;
    }        

    @Override
    protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception
    {
        ModelAndView mv=new ModelAndView("Temp", "validationForm", errors.getTarget());
        return mv;
    }
}

There is no question about form-validation. It works fine. The only question here is that when I use the showForm(...){...} method as shown above, the error messages are not displayed because this method calls when the JSP page is loaded and also, after the onSubmit() method completes (In case, the page is submitted by clicking the submit button on the JSP page).

When the page is submitted by clicking the submit button, the command object which is errors.getTarget() (or getCommand(request)) in the showForm() method (which is called after the onSubmit() method) contains no error messages to be displayed on the page. The command object (or domain object) is different from the command object in the onSubmit() method. (and therefore, when the showForm() method is commented out, it displays error messages)

I need to use the showForm() method to display a list of data from the database when the page is either submitted or loaded.

Of course, the referenceData() method as shown below does the trick.

protected Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception
{    
    Map map=new HashMap();
    return map;
}

but I want to stick at the showForm() method. Is there a fair way to display error messages while using the showForm() method while validating a form?

  • 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-06-06T20:37:23+00:00Added an answer on June 6, 2026 at 8:37 pm

    In your client-side, you can use the contents of error object to display errors, along with the form. Note that onSubmit() and showForm() are deprecated in spring 3.0.

    @SuppressWarnings("deprecation") 
    final public class Temp extends SimpleFormController 
    {         
        public Temp() 
        { 
            setCommandClass(ValidationForm.class); 
            setCommandName("validationForm"); 
        } 
    
        @Override 
        protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception 
        { 
            ValidationBean validationBean=(ValidationBean) command; 
            ModelAndView mv=new ModelAndView("Temp", "validationForm", validationBean); 
            if(errors.hasErrors()) 
            { 
                System.out.println("error"); 
                errors.reject("error.server.error");
                return showForm(request, response, errors);
            } 
            else 
            { 
                System.out.println("name = "+validationBean.getUserName()); 
            } 
            return mv; 
        }         
    
        @Override 
        protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception 
        { 
            ModelAndView mv=new ModelAndView("Temp", "validationForm", errors.getTarget()); 
            return mv; 
        } 
    } 
    

    Sample JSP code:

    For example in jsp if you need to display error messages you can use like:

    <span class="error">${error}</span>
    

    error is the attribute which we need to set in spring.

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

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words

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.