possible pattern for validation of page
2 posts in topic
Flat View  Flat View

Posted By:   Strelok_Strelok
Posted On:   Friday, July 15, 2005 11:13 AM

I have to validate a form with a lot of fields and the was wondering if there was a better way to do this rather than just a long list of "if" statements. Would it be better to use a strategy for this to separate the code. Any suggestions for other ways?


Re: possible pattern for validation of page

Posted By:   Shaun_Childers  
Posted On:   Tuesday, August 30, 2005 09:50 AM

There are a few ways to accomplish this:

1. Using Struts, you can use the Validator.

2. Using a custom servlet, you can use if statements (not recommended).

3. Using Spring, you can wire Interceptor objects that can intercept and validate the "posted" data before it reaches your controller object.

4. You can use AJAX and perform validation as the person enters data in each field (tedious).

Whatever you choose, I'd recommend separating the validation code from your controller objects. The controller should only take the information and route to the business tier and should not concern itself with validation.

Validation logic can also be in the form of a rules engine to get around the if statements.

Re: possible pattern for validation of page

Posted By:   Anonymous  
Posted On:   Tuesday, July 26, 2005 05:52 AM

Struts offers a really nice way using the ValidatorForm / ValidatorActionForm objects. Validation rules and errors are defined in xml outside of the code.

See: The Strust Validator Guide
About | Sitemap | Contact