• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Validation before conversion

 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to perform validation before conversion is atempted?
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Solution: Custom Converter?
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Daniel Prene:
Solution: Custom Converter?



Yeah, you got it.
reply
    Bookmark Topic Watch Topic
  • New Topic