File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating an instance of Errors interface.

 
Chinmay Bajikar
Ranch Hand
Posts: 159
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I was wondering if there would be any way to create an instance of the "org.springframework.validation.Errors" object.
I know that Errors is an interface.
The problem is, I have got a validator class that I would like to reuse for my other code.(by calling the validate() method).

I know the right way would be to separate the validation logic from the validator so that the logic can be used wherever.

But right now I am trying to provide something quick and dirty, so was wondering about doing this.

Thanks in advance,
Chinmay
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create a DataBinder for the object you are validating, create a MutablePropertyValues object, set the values you want to set on the object by calling mutableProperties.add("propertyName", value), call dataBinder.apply(mutablePropertyValues) to attempt to bind the values to the target object, then call dataBinder.getBindingResult() - this returns an instance of a BindingResult, which also implements the Errors interface. The BindingResult returned originally contains any errors that occurred during the bind, like any conversion/casting errors on the values, but now you can also use the BindingResult to use in your Validator's validate(target, errors) method.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic