This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Spring and the fly likes Create a Validator using .properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Create a Validator using .properties file" Watch "Create a Validator using .properties file" New topic
Author

Create a Validator using .properties file

Anupam Dee
Ranch Hand

Joined: Oct 18, 2010
Posts: 42

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.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

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.


[How To Ask Questions][Read before you PM me]
 
 
subject: Create a Validator using .properties file
 
Similar Threads
Spring Dependency Injection in JSF Validator
Creating a Properties file and calling them
To Authors - Exception Handling in JSF
Reading a properties file using BufferdInputStream
Appending command object to properties in properties file and throwing an error