Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC <form:errors/> tag doesn't find error messages

I work with a front-end developer who writes JSP files. We have a form that is working correctly, except validation/binding/processing errors can't seem to be displayed with Spring's <form:errors/> tag.

I've confirmed that the error is being set, and what is apparently the correct path for the errors. Supposedly <form:errors path="*" /> should render them all, regardless of path, but it shows nothing.

Do I need to get into the tag library source to deduce what's going wrong?

like image 985
Mojo Avatar asked Sep 01 '09 17:09

Mojo


People also ask

How to display error message in Spring MVC?

The Simple Steps Specify a single URL /errors in web. xml that maps to a method that would handle the error whenever an error is generated. Create a Controller called ErrorController with a mapping /errors. Figure out the HTTP error code at runtime and display a message according to the HTTP error code.

What are spring form tags?

The Spring MVC form tags are the configurable and reusable building blocks for a web page. These tags provide JSP, an easy way to develop, read and maintain. The Spring MVC form tags can be seen as data binding-aware tags that can automatically set data to Java object/bean and also retrieve from it.

What is default controller in Spring MVC?

The default handler is based on the @Controller and @RequestMapping annotations, offering a wide range of flexible handling methods. With the introduction of Spring 3.0, the @Controller mechanism also allows you to create RESTful Web sites and applications, through the @PathVariable annotation and other features.

What is view in Spring MVC?

The view is a component of MVC architecture that is used to return a user interface output to the user in response to the user request. A View page can be any HTML or JSP file. Spring MVC internally uses a view resolver to fetch the requested view to the user.


2 Answers

2 things I discovered.

1) make sure you specify the name of the form-bean / command object in the form tag

<form:form method="post" enctype="multipart/form-data" commandName="salesOrder">

2) make sure you name your form-bean / command object by its class name. In the example above my class is com.abc.xyz.SalesOrder. If I call it "so" or "order" in the model then it will not show the errors.

like image 103
Derek Avatar answered Oct 23 '22 08:10

Derek


Simple answer: <form:errors/> must be within a <form:form/> element in order to bind to the model's "command" object.

like image 29
Mojo Avatar answered Oct 23 '22 09:10

Mojo