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 JSF Vs JavaScript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF Vs JavaScript" Watch "JSF Vs JavaScript" New topic
Author

JSF Vs JavaScript

MaheshS Kumbhar
Ranch Hand

Joined: Sep 24, 2009
Posts: 188
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?


I am slow but sure
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

And by the way, your picked subject for your post is too much misleading.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

John Todd wrote:And by the way, your picked subject for your post is too much misleading.


Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

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

Joined: Dec 28, 2006
Posts: 893
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.


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF Vs JavaScript