permaculture playing cards*
The moose likes Other Application Frameworks and the fly likes Spring MVC commons-validator - Over riding default messages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Spring MVC commons-validator - Over riding default messages" Watch "Spring MVC commons-validator - Over riding default messages" New topic
Author

Spring MVC commons-validator - Over riding default messages

Tauri Valor
Ranch Hand

Joined: Aug 03, 2005
Posts: 166
Hi

Im using Spring MVC with commons-validations for validations.

I have a problem overriding the message in validator-rules.xml.

I have my messages.properties in classpath, but still I have only the default error message printed on my page for validator-rules.xml.

The following is my code:

validator-rules.xml:
----------------------



validator.xml:
-----------------


messages.properties:



I have only the default error message "errors.required" printed.

Instead I should read the properties file which I couldnt.

Please let me know if theres any error in my approach.


Regards,
Tauri


A Moment's insight is sometimes worth a Life's experience.
Tauri Valor
Ranch Hand

Joined: Aug 03, 2005
Posts: 166
I missed the default validation message in my Resource bundle.

I included the line:

errors.required = {0} is required

and in my validator.xml arg0 is : <arg0 key="loginForm.Password" />

But I still get the message as : "{0} is required"

Instead I should display the error as Password is required, since 'Password' is the arg0 .

Please help.
Johnny Gara
Ranch Hand

Joined: Mar 09, 2007
Posts: 43
I'm not entirely sure about why your arg's aren't being passed in, but why are you even passing in the word Password? Why don't you simply have it say "Password is mandatory"?

If your worried about internationalization (which I can't see since you left english words), then you might have an issue...
Tauri Valor
Ranch Hand

Joined: Aug 03, 2005
Posts: 166
I finally got the validation working both client and server side after many changes in my configuration.

Thanks to you for responding to my message

However I have another query related to this.

As of now,I have all my validations diplayed as list at the top or a bunch of validations in an alert.

Can I have the validation per field under each field ? How can I achieve this..might be simple

Thanks again.
Johnny Gara
Ranch Hand

Joined: Mar 09, 2007
Posts: 43
I'm not really familiar with the commons.validator package, but usually it simply involves you referencing the correct error in your error variable.

If you are seeing all the errors, you are probably outputting your errors like (this is in STRUTS taglib):
<html:errors/> would normally print out all errors

while:
<html:errors property="cellphone" />

would print out errors simply for the errors.cellphone

Not sure if that entirely helped, but that's probably very close to how it works in commons.validator.
Tauri Valor
Ranch Hand

Joined: Aug 03, 2005
Posts: 166
Johnny,

You are right. I figured it out, but my page looks clumsy as I have to allocate place for each error below my field. I think I need a <div>.

Any other solution?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring MVC commons-validator - Over riding default messages