I use a bean as a transfer object between the form validator and the dao.
There is one form validator object per form. The form validators all inherit
from a superclass object. The superclass object contains shared
functionality such as zipcode validation routines, credit card mod 10
checks, required fields, error display etc. Each form validator object is
responsible for setting up the form fields, and how each one should be
validated and returns the transfer object with complete information if
validation was successful or formHasErrors flag.
A manager object is responsible for taking the form variables, instantiating
the appropriate form validator object, passing in the form variables,
getting the completely filled out transfer object out of the form validator
and passing it into the dao object for entry into the database.
Alternatively, in case there were errors, it loads in the form page
containing the html for the form and passes it this form validator object.
The page has calls to getError("fieldName") from the form validator object
which will display the error or an empty string if there was no error for
that particular field.
ed
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of Dawson, Michael
Sent: Friday, January 28, 2005 8:55 PM
To: [email protected]
Subject: [CFCDev] Validating and Persisting Form Data
This was previously discussed in the "Validation" thread back in
November, but I never really "got it". This list has several new
members so I would be interested in hearing new solutions, not that I
discount the "elder's" opinions. ;-)
I have a web-based form and I need to persist the data in a database. I
also want to validate the data and, if there are errors, reload the form
and display the errors to the user. (The form is self-posting to make
it easier to re-populate the fields with just-submitted data.)
I also have a simple bean that contains only getters and setters that
equate to the form fields. The setters are all "typed" (e.g. String,
Numberic, etc.) according to the requirements. (This is the data that
needs to be validated, eventually, before saving to a database.)
I have a DAO that Creates, Updates and Deletes a single record in the
database. (This DAO does not validate any data. It only assumes the
data passedto it has already been validated.)
This is my current situation as mentioned above:
TheForm -> Bean -> DAO -> Database
If I need to validate the data from the form, where would the logic
reside?
Should I use:
TheForm -> TheFormValidationObj -> Bean -> DAO -> Database
Or, do I put the validation in one of the existing layers? Keep in mind
that I will probably need to reuse some of the validation functions for
other objects.
If anyone could post a fully-working sample of this simple application,
I'm sure many others would greatly appreciate it.
I have a simple working application, but, being new to any OOP thinking,
some things just don't "feel right" to me.
Thanks
M!ke
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]