Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF Vs JavaScript

 
MaheshS Kumbhar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a new learner of JSF.
I have a very basic question.
If JavaScript can do form validation at client side then why to use JSF to do the same thing on server side which incurs network traffic?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18272
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Because sometimes people turn JavaScript off, for one reason or another. Including dire Microsoft security alerts about the latest JavaScript-related exploit.

2. Because trusting the client to provide sane data is insane. A considerable percentage of security exploits work because someone has hacked the client-side processing to return unexpected data in the hopes of breaking the server.

Use JavaScript to provide a faster user feedback. Use server-side validation to protect yourself. If you're using JavaScript as your first line of defense, you won't have to pay the server validation overhead until all client-side edits have permitted the server request to go through. And at that point, the "network traffic" is the data being updated, so there's no real penalty.

The one penalty you do pay of course, is in whatever work you do to duplicate the validation, But that extra investment in robustness is what separates the "toy" programs from enterprise-grade applications and why the hypothetical 10-year old kid isn't the equivalent of a trained software developer.

Of course, if you use a JSF tagset that can automatically generate both the client- and server-side validations from the same specifications, I won't stop you. In fact, I'm always on the lookout for tools of that type.
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And by the way, your picked subject for your post is too much misleading.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18272
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Todd wrote:And by the way, your picked subject for your post is too much misleading.


 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:
John Todd wrote:And by the way, your picked subject for your post is too much misleading.



When I read the subject, I thought he is asking about JavaScript -the language- and JSF -the framework- but it turns out that he is asking about client-side validation and why to duplicate it on the server.
 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use javascript sometimes for updating calculated values in a form before submitting the form. In this way a customer can see what the effects of his actions are if the form is submitted. Par example I subtract the total inventory in the webpage when the customers uses a part within the inventory. This would be the inventory if the action is submitted and processed. Changing colors depending on the values is an another application of javascript.

Thereby I have a small change that the final submit fails, but normally this will not be the case.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic