This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validation before conversion

 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to perform validation before conversion is atempted?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why you want to do that?

You can validate in your converters. Validate first and then convert it. Validators are there to validate business logics. Assume this scenerio, you want a value between 100 to 700. Here you want to convert that string to Integer than validate that business logic. If you place the validator before convertor then in that case validator needs to convert it first before validation. And it is the death of converters.

Sometimes you want to validate first before conversion. That case could be you want date in a particular format. Here you need to validate the format and then convert it to the Date object. This kind of things you can do in your converters. Here the validator doesn't check your format but validate your business logic, like the date should be greater than todays date or something. But it doesn't mean that a validator doesn't check the format. I am just saying that if you have a converter associated with some date component then your converter will check the format kind of things.

This is what I understood. More inputs are greatly appreciated.

Thanks.
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason I was asking was because I craved a better more meaningfull conversion error. I could only find articles on how to change the default... and that's still unhelpfull.. I don't actualy need to do more then convert a string to an integer, but I want the user to know they didn't enter an integer.
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solution: Custom Converter?
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for replying by the way. I realy apreciate it
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Daniel Prene:
Solution: Custom Converter?


Yeah, you got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic