Exforsys

Online Training

possible pattern for validation of page

This is a discussion on possible pattern for validation of page within the Software Patterns forums, part of the Testing category; Hello, I have to validate a form with a lot of fields and was wondering if there was a better ...


Go Back   Exforsys > Testing > Software Patterns

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-18-2005, 11:07 AM
ryanferretti@gmail.com
Guest
 
Posts: n/a
possible pattern for validation of page

Hello, I have to validate a form with a lot of fields and 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?
Thanks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-20-2005, 02:41 AM
pven
Guest
 
Posts: n/a
Re: possible pattern for validation of page

Hi,

I am not able to suggest a pattern, however I found the
apache struts framework very modular for validation and error handling.


To just give a breif overview of struts, (just in case you
are not aware of struts)...

In struts, for every page we define a class that will hold
all the fields in the page.

Lets say the page has an input field called "name".
In sruts, we will have a class for that page

class Page extends ...{

string name ;

void setName (String name ) {

}

string getName() {
return name ;
}

}

When the form is posted, the struts engine creates
an object of this class Page and pushes the value provided
in the field name to the member variable name by calling the setName().

This Page object also has a method called validate()
where we can write the code to check if the fields in
the form are of the right type. Again, there would be if else...
This validate() method is automatically called by the struts engine...

If there are errors in validation, struts has a neat way to throw
the error back in an elagant manner.. ( error message is read from
an message file)

Back,

I don't think this is the appropriate answer to your query
but I found the struts framework very neat when building jsp pages.

Previously, I had the validation and business logic in the jsp,
and when there was a requirement change I needed to go through
a lot of pain to understand the flow in a jsp that was packed with
everything but with struts things became simpler....

Prasanth

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-20-2005, 03:48 PM
ryanferretti@gmail.com
Guest
 
Posts: n/a
Re: possible pattern for validation of page

Thanks for the reply, I have had experience with using struts and had
considered it with for this project. We decided on using Sping MVC
instead of struts because of what it offers.

Ryan

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 11:20 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.