aspose file tools*
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
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: 1680
    
    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]
 
Don't get me started about those stupid light bulbs.
 
subject: Create a Validator using .properties file