geeky · non php code

SpringMVC generic errors

I was looking around the net for this. Maybe I didn’t look hard enough but I wasn’t able to find it. Finally a coworker told me. If you use the SpringMVC framework and wish to show generic validation error messages at the top of the page, here’s how you do it:

<spring:hasBindErrors name="formName">
  <div class="genericErrors">
  <span class="errorRight">
	      <c:when test="${errors.errorCount > 1}">
		    There are ${errors.errorCount} errors. Please correct them.
		    There is ${errors.errorCount} error. Please correct it.
	Scroll down if necessary to see all of the error messages in red.

Obviously if you wish to display specific error for a field, you’d use

<form:errors path="yourInputName" />

To read more about error handling in SpringMVC, read the chapter 13 of its documentation.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s