• Post Reply Bookmark Topic Watch Topic
  • New Topic

modern J2EE and javascript

 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all:
I am working on a project that was developed by other people. The project architicture is relaying on javascript to format proper output and input. I believe it is such a bad design. However, I want to know from the Java gurus who worked on enterprise level project if it is ok to use it or not. Is it a common practice when developing a web project? what is the advantages, and disadvantages?
thanks
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the question whether you should use Javascript in a web project? The answer is yes -- Javascript browser compatibility issues have been mostly resolved, and it's the *best* way to do validation of forms at the browser prior to submitting a form to the server....
Kyle
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kyle Brown:
and it's the *best* way to do validation of forms at the browser prior to submitting a form to the server....

At which point your JSP/servlet/bean/whatever should promptly *validate* the input. Using Javascript to format/tweak stuff in the browser is great for creating a better user experience (fail-fast form validation, possibly faster page loads, other fancy stuff), but you should expect that at some point someone will bypass your validation logic and submit a form with invalid data.
Even if this is an internal project where you could theoretically trust your users not to do this kind of stuff, it's still a best practice to do the "extra" validation in case you end up using that same code elsewhere or if there are bugs in the JS code.
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with David. We should not relay on the presentation layer to do the validation of data. What bugs me with the project I am working on right now is that: the developers who designed it not only relaying %100 on javascript to validate I/O, they also designed so that some function of the program won't work without javascript. We have realy major bugs in that project, but sadly enought it is in productin now, and I can't do anything about it.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amen, amen and amen. I didn't say *only* rely on the Javascript to do validation. I would advocate revalidating again at the Servlet/JSP layer, and yet another time at the EJB layer if you have one...
Basically, programmers can't trust anybody. If you assume your validation has been handled at a layer above your code you will inevitably find out you were wrong...
Kyle
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!