Dashboard > Spring Discuss > Working with Spring MVC > Struts Standard Error Messages
  Spring Discuss Log In View a printable version of the current page.  
  Struts Standard Error Messages
Added by Matt Parker, last edited by Matt Parker on Jul 05, 2005  (view change)
Labels: 
(None)

Struts Standard Error Messages

Many people used to Struts will be wondering how to create similar functionality to the standard Struts error messages such as "X is a required field". The problem is that "X" is more than likely to be an internationalised text string as well as the error message body. The following describes how to create "nested" internationalisation lookups within error messages.

Example

Say the following is the contents of the error messages properties file.

error.required={0} is a required field
label.firstname=First Name

This can be resolved within the Spring validation framework as follows.

errors.rejectValue("myfield",
  "error.required",
   new Object[] {new DefaultMessageSourceResolvable(new String[] {"label.firstname"})},
  "First Name is a requred field");

How could this be done for when a property editor rejects a value for being a typeMismatch without writing a custom PropertyEditor?

Site running on a free Atlassian Confluence Open Source Project License granted to Spring Framework. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.5 Build:#811 Jul 25, 2007) - Bug/feature request - Contact Administrators