|
I tend to put extra data into instance
variables in the custom record and create getters/setters for them. They won’t
be persisted, but they can be used in validation like this. Doug From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dan Vega I figured out how to do
that from one of the list archive, but thanks for your input. I am still
running into a validation issue though. Say you have an EmailAddress field in
your database but your form has an emailaddress & emailaddress2 for validation
that the user is correctly entering their email address. When you get to
setEmailAddress( form.emailaddress) that works fine but you can't
setEmailAddress2(form.emailadress2) because its not a database field nor should
it be. So that begs the question how can extend validation for a field that
does not belong in our database. I am just wondering if anyone has run into
this because I could see myself doing this in many places. On 7/8/06, Erik-Jan
Jaquet <[EMAIL PROTECTED]>
wrote: Hi Dan, Waht I have done, is the following: -
in the 'reactor-created' cfc's find the validator
cfc for the object that you want to add to. -
In this cfc, add a function for the field you
want to add to, for instance validateUser -
First call <cfset
super.validateEmail(arguments.UserRecord, arguments.ErrorCollection) /> to
run all the reactor validation -
Then add calls to your own functions, that you
can add below the function you are in know. My CFC looks like this: <cfcomponent hint="I am the validator object for the
User object. I am generated, but not overwritten if I exist. You
are safe to edit me."
extends="reactor.project.cello.Validator.UserValidator">
<!--- Place custom code here, it will not be overwritten --->
<!--- validateEmail --->
<cffunction name="validateEmail" access="public"
hint="I validate the Email field" output="false"
returntype="reactor.util.ErrorCollection">
<cfargument name="UserRecord" hint="I am the UserRecord to
validate." required="no"
type="reactor.project.cello.Record.UserRecord" />
<cfargument name="ErrorCollection" hint="I am the error
collection to populate. If not provided a new collection is created."
required="no" type="reactor.util.ErrorCollection"
default="#createErrorCollection(arguments.UserRecord._getDictionary())#"
/>
<cfset super.validateEmail(arguments.UserRecord, arguments.ErrorCollection)
/>
<!--- validate Email is unique --->
<cfset validateEmailIsUnique(arguments.UserRecord,
arguments.ErrorCollection)>
<!--- validate Email is correct --->
<cfset validateEmailIsCorrect(arguments.UserRecord,
arguments.ErrorCollection)>
<cfreturn arguments.ErrorCollection />
</cffunction>
<!--- validateEmailIsUnique --->
<cffunction name="validateEmailIsUnique" access="public"
hint="I validate that the email field is unique"
output="false" returntype="reactor.util.ErrorCollection">
<cfargument name="UserRecord" hint="I am the UserRecord to
validate." required="no"
type="reactor.project.cello.Record.UserRecord" />
<cfargument name="ErrorCollection" hint="I am the error
collection to populate. If not provided a new collection is created."
required="no" type="reactor.util.ErrorCollection"
default="#createErrorCollection(arguments.UserRecord._getDictionary())#"
/>
<cfset var UserGateway =
_getReactorFactory().createGateway("User") />
<!--- insure that another user with the same username does not already exist
--->
<cfif UserGateway.validateEmail(arguments.UserRecord.getUserId(), arguments.UserRecord.getEmail())>
<cfset arguments.ErrorCollection.addError("User.email.duplicateEmail")
/>
</cfif>
<cfreturn arguments.ErrorCollection />
</cffunction>
<!--- validateEmailIsCorrect --->
<cffunction name="validateEmailIsCorrect"
access="public" hint="I validate that the email field is a
correct emailaddress" output="false" returntype="reactor.util.ErrorCollection">
<cfargument name="UserRecord" hint="I am the UserRecord to
validate." required="no"
type="reactor.project.cello.Record.UserRecord" />
<cfargument name="ErrorCollection" hint="I am the error
collection to populate. If not provided a new collection is created."
required="no" type="reactor.util.ErrorCollection"
default="#createErrorCollection(arguments.UserRecord._getDictionary())#"
/>
<cfif NOT
isValid("Email", arguments.UserRecord.getEmail())>
<cfset arguments.ErrorCollection.addError("User.email.InCorrectEmail")
/>
</cfif>
<cfreturn arguments.ErrorCollection />
</cffunction> </cfcomponent> I believe this is copied from the MG / Reactor Blog sample
from the Reactor site. Good luck! Erik-Jan Van: [EMAIL PROTECTED]
[mailto:
[EMAIL PROTECTED]] Namens Dan
Vega Does
anyone have an example of custom validation? I do not wish to overwrite the
curret validation,just to extend it. I have a userRecord that contains a bunch
of basic info that reactor is already validating. I would like to aded custom
validation so i can find out if
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Reactor for ColdFusion Mailing List [email protected] Archives at: http://www.mail-archive.com/reactor%40doughughes.net/ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
- [Reactor for CF] Extended Validation Dan Vega
- RE: [Reactor for CF] Extended Validation Erik-Jan Jaquet
- Re: [Reactor for CF] Extended Validation Dan Vega
- RE: [Reactor for CF] Extended Validation Doug Hughes
- Re: [Reactor for CF] Extended Validation Dan Vega
- Re: [Reactor for CF] Extended Validation Dan Vega
