GeeCON Prague 2014*
The moose likes JSF and the fly likes Validation before conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSF
Bookmark "Validation before conversion" Watch "Validation before conversion" New topic
Author

Validation before conversion

Daniel Prene
Ranch Hand

Joined: Jul 15, 2005
Posts: 241
Is it possible to perform validation before conversion is atempted?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Jul 15, 2005
Posts: 241
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

Joined: Jul 15, 2005
Posts: 241
Solution: Custom Converter?
Daniel Prene
Ranch Hand

Joined: Jul 15, 2005
Posts: 241
Thank you for replying by the way. I realy apreciate it
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Daniel Prene:
Solution: Custom Converter?


Yeah, you got it.
 
GeeCON Prague 2014
 
subject: Validation before conversion