During his television and writing career, Art Linkletter perfected the art of eliciting unexpected and humorous responses from children. For example, when asked how his parents met, one eight-year-old boy replied, “My father was doing some strange chores for my mother. They won’t tell me what kind.” Indeed, as Linkletter said, “Kids say the darndest things!”
During his television and writing career, Art Linkletter perfected the art of eliciting unexpected and humorous responses from children. For example, when asked how his parents met, one eight-year-old boy replied, “My father was doing some strange chores for my mother. They won’t tell me what kind.” Indeed, as Linkletter said, “Kids say the darndest things!”
Today, if Linkletter were a Web programmer, he’d probably say, “Users type the darndest things!” However, he wouldn’t be laughing. Validating user input — necessary to prevent bad form data from crashing applications, polluting databases, or causing other harmful side effects — is one of the most time-consuming, tedious, and thankless tasks in Web programming.
Thankfully, the new version of Jakarta Struts (described in last month’s issue or available online at http://www.linux-mag.com/2002-03/struts.html) supports an innovative (and arguably easier) way to check user input: the Commons Validator. The Validator allows you to validate form data declaratively, using an external, XML configuration file instead of Java code. By excising validation from your application, you can make changes to your form and to the associated validation method without recompiling your code. Even better, the Validator can be used on any Java project — on or off the Web.
This month, let’s continue looking at Struts 1.1 and take an in-depth look at the Validator. If you don’t have Struts yet, you can download it and its extensive set of documentation from http://jakarta.apache.org/struts.
Doing It the Old-Fashioned Way
Prior to Struts…
Please log in to view this content.
Not Yet a Member?
Register with LinuxMagazine.com and get free access to the entire archive, including: