Form Validation

UI Components for JSF
Post Reply
bsanders1979
Posts: 69
Joined: 02 Jun 2013, 18:37

08 Apr 2014, 06:42

Greetings,
I am working on a technique involving validation of complex objects. Basically, the idea is to serialize everything into an inputHidden as a Base64 JSON string, write a converter and then pass the object to a validator. I was hoping I might get a little feedback on such an approach as to not re-invent the wheel, or whether there are better ways of doing it. Currently, such validations are occcurring in the "bean"/"View Model" and I'm unsure if they belong in the JSF validation phase. I realize this isn't exactly a PF question, but any feedback would be much appreciated. Thanks!

Brian Sanders
PF 5.0
PF Ext 0.7.1
OmniFaces 1.7
Tomcat 7.0.37
JSF 2.1.24

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

08 Apr 2014, 11:47

No need to go to all this trouble, you can simply create either a custom Validator for this, create validation Methods which throw ValidationExceptions (useful for checking multiple fields) or utilise Beans Validation.
Validation should only be carried out in the validation phase otherwise the JSF lifecycle can get out of whack. You can, of course, do things like complete class graph checks before saving, set the FacesContext.validationFailed flag and add a message accordingly so that extra validation does the right thing on the client side without breaking the lifecycle.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

bsanders1979
Posts: 69
Joined: 02 Jun 2013, 18:37

18 Apr 2014, 18:28

Hey Andy,
Thanks for your insight. The one thing that caught my eye in particular was the FacesContext.validationFailed part. I will certainly look into that.
PF 5.0
PF Ext 0.7.1
OmniFaces 1.7
Tomcat 7.0.37
JSF 2.1.24

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

18 Apr 2014, 21:20

By the way, I'm working right now on a GraphValidator for Bean Validation on the model class level. It will be a part of PrimeFaces Extensions https://github.com/primefaces-extension ... issues/225 It will be possible to validate any complex object in the validation phase. I hope at least.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

bsanders1979
Posts: 69
Joined: 02 Jun 2013, 18:37

20 Apr 2014, 05:56

Sweet! Will it work with 3.5?
PF 5.0
PF Ext 0.7.1
OmniFaces 1.7
Tomcat 7.0.37
JSF 2.1.24

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

20 Apr 2014, 09:33

Sweet! Will it work with 3.5?
Do you mean GraphValidator? Theoretically yes, but it will be in PF Extensions > 2.0.0 which is built on top of PF 5.0. You can only use it with PF 5.0 or later.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 26 guests