File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Validators still required to throw exceptions? :( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Validators still required to throw exceptions? :(" Watch "Validators still required to throw exceptions? :(" New topic
Author

Validators still required to throw exceptions? :(

Jason Porter
Ranch Hand

Joined: Apr 26, 2007
Posts: 120
Validators are still supposed to throw the ValidatorException? Was it talked about removing this and perhaps switching to a boolean based validation strategy?
Andy Schwartz
Greenhorn

Joined: Feb 04, 2010
Posts: 4
Hey Jason -

Yep, validators still throw exceptions to report validation failures. I don't remember much discussion on this topic - at least not since I joined the EG.

Is your concern primarily that this is an abuse of exceptions (from an API design standpoint)? Or is there some functionality that you are hoping to achieve that isn't currently possible to implement with the exception-based API?

Andy
Jason Porter
Ranch Hand

Joined: Apr 26, 2007
Posts: 120
Is your concern primarily that this is an abuse of exceptions (from an API design standpoint)?


This one. I'm pretty sure you could still continue with the rest of the lifecycle (not really sure where it would make sense though if you don't pass validation). It doesn't seem like it would be much work to have Validatior.isValid(...) then have the impl add the faces message(s).

Maybe this isn't really an issue any more with Bean Validation though.
Andy Schwartz
Greenhorn

Joined: Feb 04, 2010
Posts: 4
Jason Porter wrote:I'm pretty sure you could still continue with the rest of the lifecycle (not really sure where it would make sense though if you don't pass validation). It doesn't seem like it would be much work to have Validatior.isValid(...) then have the impl add the faces message(s).


Well... the validator exceptions are caught pretty much immediately (handled locally by UIInput), so it's not so much that the use of the exception is preventing further processing, though I understand your concerns about this use of exceptions from an API perspective.

Maybe this isn't really an issue any more with Bean Validation though.


Bean validation is nice as it allows you to free up your page from validation logic/tags. Should result in cleaner pages and more centralized validation logic. Though, of course, we're still throwing exceptions under the covers.

Andy
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Validators still required to throw exceptions? :(