0

There is the JSF validation framework - the JSF Validators and the validation phase, in which they run. So far my intuition was, they are designed mostly for simple, local, independent checks - regex test, number validation, etc.

But then comes the question - how should the the complex validation scenarios be realized? By complex I mean: some long-running checks with possibly heavy backend calls (DB, WS) and side-effects involved. By how I mean: do they also fit into the validation framework?

What I have seen so far, is that people rather lean towards here into invoke application phase and custom error handling. And here comes the ugly part - custom error handling, so either coupling into JSF API (invalidating components, setting messages) or rendering everything by hand (independent of h:messages) - i.e. struggling hard only to mimic the already existing solution.

So the question is less about technical feasibility (defining validators) and more about best-practices.

Thx, Jarek

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
jarek.jpa
  • 556
  • 1
  • 4
  • 17
  • 1
    Have you also looked at the technical reason why some (more than often ignorant) people do it in invoke application phase? By default, it isn't possible to inject business services (e.g. EJBs) in validators, forcing them to do the job in a managed bean instead. However, if you make it possible (there are workarounds, solutions and even libraries for that), then you could just continue using validators for that the usual (right) way. – BalusC Oct 28 '13 at 10:43
  • 1
    Obligatory link: Injection in [custom FacesConverter](http://stackoverflow.com/a/7665768/785663) and [custom FacesValidator](http://stackoverflow.com/a/7572413/785663). Personally, I loved seeing transparent support for CDI in Omnifaces making this a non-issue and allowing validation to stay where it belongs. – mabi Oct 28 '13 at 10:54
  • Yes, you're right @BalusC, that's the most often reason. I am aware of the fact, the overcoming this (so getting DI right) is possible, but wanted to ask whether this is the right way. Imagine the validation check has some side effects - like storing the positive validation result. So the other way - how far do we want to couple the validator with the business logic? – jarek.jpa Oct 28 '13 at 10:57
  • Depends on the functional requirement behind storing the positive validation result of the particular validation. Even JSF has standard ways for this. – BalusC Oct 28 '13 at 10:58
  • OK, fair enough. You can post your opinion, that it is perfectly ok to use validators here, as a reply - unless there come some alternatives, I will be happy to accept it as an answer. – jarek.jpa Oct 28 '13 at 12:28

0 Answers0