Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF client side validation

 
Christian Nicoll
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

more than 6 years ago I worked last time with JSF 1.2. At this time the default validation mechanism just happened at the server and not a the client. If someone would like to add an additional client-side validation through Ajax, he was responsible to implement it on his own. Is this with JSF 2.0 still the case, or is there something like an automated client-side validation that would also generate this JavaScript code? Finally this would mean from my understanding that the same checks would executed twice (at client- and at server-level).

Regards,
Christian
 
Matt Keller
Ranch Hand
Posts: 32
1
Eclipse IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know, even in JSF 2.0 its all server side.  So for client side validation you either have to roll your own or find a suitable js library.  I rolled my own for a company years ago and haven't found anything better than what we developed because you want a full featured client side js framework to be able to provide the following.

1) color the offending inputs
2) provide popups next to the inputs upon focus to tell what the problem is
3) validate all inputs at the same time so the user doesn't get that annoying "I'll only tell you one problem at a time behavior"
4) Internationalization
5) Unlimited custom logic
6) Built in date logic

Another thing worth noting, is that you don't want the error messages buried in your html markup the way Dojo validation does.  You want them in a javascript array because if you add a new message you don't want to have to go hit all your pages that use that validator.  I hope this helps. If you find a really awesome framework, let us know.
 
Christian Nicoll
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your feedback Matt.
 
Tim Holloway
Saloon Keeper
Posts: 18366
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, JSF still doesn't do client-side validation.

Actually, based on my experience, client-side validation for many things can end up so messy that I found it easier to use server-side validation with AJAX.

One thing you can do in JSF2 is define your own custom tags using XML and add validation javascript to those tag definitions. I recommend doing XML custom tags over binary ones because they're easier to code and not as likely to break the next time JSF's internals get overhauled.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic