• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring MVC commons-validator - Over riding default messages

 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Tauri Valor
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic