• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OO Form Validation and Error Checking

 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was looking at a flyer for the JavaTech Summit at the WebBuilder Conference in New Orleans next month, and noticed one particular seminar that caught my eye because I'll need to be writing code to do this soon: OO Form Validation and Error Checking with JSPs. Does anyone know of any existing JSP or generic libraries that do this? Or does anyone have a snippet of example code they'd be willing to share? Or a book with examples to recommend?
The main things that I see the need for in validating forms are checking for required (not null) fields, numeric-only or text-only, min/max length, and illegal or program-busting characters. Oh, and some class or something that recognizes encoded characters and converts them back to ASCII (such as %20 (percent twenty),   (non-breaking space), etc).
Quick tech question: when doing validation, do most people post back to the same JSP when the form is submitted, and then when it finally checks out OK just forward request to a different JSP or servlet?
Thanks!
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out Apache Struts at http://jakarta.apache.org/struts. One of the features to come in version 1.1 is Dave Winterfeld's Validation library that adds the kind of features you're looking for. A link to that can be found here http://home.earthlink.net/~dwinterfeldt/index.html
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
On the 'Tech Question' bit
Why not just use javascript to validate your form(JSP and/or
HTML page) before submitting it.
Cheers

Originally posted by Gerry Giese:
I was looking at a flyer for the JavaTech Summit at the WebBuilder Conference in New Orleans next month, and noticed one particular seminar that caught my eye because I'll need to be writing code to do this soon: OO Form Validation and Error Checking with JSPs. Does anyone know of any existing JSP or generic libraries that do this? Or does anyone have a snippet of example code they'd be willing to share? Or a book with examples to recommend?
The main things that I see the need for in validating forms are checking for required (not null) fields, numeric-only or text-only, min/max length, and illegal or program-busting characters. Oh, and some class or something that recognizes encoded characters and converts them back to ASCII (such as %20 (percent twenty), � (non-breaking space), etc).
Quick tech question: when doing validation, do most people post back to the same JSP when the form is submitted, and then when it finally checks out OK just forward request to a different JSP or servlet?
Thanks!


 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out a tag library called dotJ. It has exactly what you're looking for (http://www.dotjonline.com/taglib/form.jsp). It works exactly like the new ASP.Net form controls.
I always post a form back to itself since it makes it easy to redraw the form with error indicators when any validation fails.
If the validation suceeds, forward or redirect to the next page. If the validation fails, let the page redisplay with the appropriate error messages.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regarding the tech question, like Toyin said, Most people use JavaScript to do the front end validation. We also put the same validation on the back end here where I work.

Bosun
 
Gerry Giese
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Toyin & Bosun:
Can't do Javascript: the government organization I'm working for handed down an edict that all logic processing is server-side. This is partially for security reasons, but also for browser support - our official common desktop just moved from NS to IE but we have to support versions back to 3.x of both on PC/Mac/Unix as well as some misc. other. On the security side, the 'experts' want to block all Javascript on the network at some point. They already block all in/out Javascript and Applets at the internet firewall, as well as ActiveX, VBScript, etc, which means our remote extranet users wouldn't be able to use our apps if we used javascript.
From a practical point of view on security, even if you validate client-side with Javascript, it's still important to validate server-side. Anyone with a little time on their hands or a purpose can save and edit a page and change the script and post bad or malicious data to your site if you don't re-check server-side. I've seen it happen numerous times at various places - mostly with people trying to 'cheat'.
Kyle & Joe:
I'll go check those out - thanks for the links! I hope that Dave's Validation library is available seperately. Struts is good but we've already gone another direction on a templating engine. Haven't done JSP tags yet, so I'll have to try that out. Should work with our setup since we're still JSP-based.
Thanks all! Anyone else have 2 cents to add?
 
Gerry Giese
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another reason not to use javascript: especially on large forms (we have lots) it can double or more the downloaded page size. Slow page loads are always bad and can amplify the reduced response time of a slow or loaded server.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more quick thing...
In my oppinion, for robust code its best to implement both client-side and server-side form validation for redundancy. Bugs appear quicker and you can't always guarantee that the user will have client-side scripting available/enabled. In your case this decision has been made for you.
As the guys said above, Struts is a good bet although, it is about a lot more that just form validation.
If you prefer to read things on paper than on the web then you might like to buy "Advanced JavaServer Pages" by David M. Geary (ISBN 0-13-030704-1) http://www.phptr.com/advjsp
This book covers OO form validation and a full blown form framework. It also covers a whole host of other indispensible topics on web application frameworks etc. The author David M. Geary is one of the Committers on the Jakarta Struts project and unsurprisingly the techniques described in the book are strikingly similar to the implementation of Struts!!!
However, it has the advantage of letting you read about and understand just the bits you want - form validation - and ignore the rest of the framework.
On a side note. The CURRENT version of Struts is far from perfect, especially when it comes to client-side validation - but you don't need to worry about that. There are also other viable application frameworks out there.
Andre.
PS.
On your tech question, Struts might lead you to take a slightly different approach.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic