This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP and have Lucian Maly on-line!
See this thread for details.
Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Create a Validator using .properties file

 
Ranch Hand
Posts: 42
Firefox Browser Tomcat Server Windows XP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to create a Validator class e.g PersonValidator that implements Validator interface. I want to get the error messages stored in the .properties file (for Internalization).
I am trying to autowire MessageResource to do the same.



this is the xml content


and this is main

and the output is
null
[Field error in object 'person' on field 'name': rejected value [null]; codes [name.required.person.name,name.required.name,name.required.java.lang.String,name.required]; arguments []; default message [null]]

the first null is messageSource getting printed and it is null !
I think i am not able to autowire the messagesource to the .properties file. How should i do it?
Any help would be appreciated.

Thanks in advance.
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MessageSource is null because it is not a Spring managed bean you are creating it using the new operator. Get it from the context instead.


Of course you will first have to make sure that the "personValidator" bean is defined in your context and you are wiring the messageSource into it. You could do this by adding an @Component to the PersonValidator class and adding a component scan or you could just wire it up manually.
 
I'm not sure if I approve of this interruption. But this tiny ad checks out:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic