So the custom validatate method is just a validate() function within my Record object? Or does it have a different name?

 

Cedric

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Doug Hughes
Sent: Sunday, February 26, 2006 7:57 AM
To: [email protected]
Subject: RE: [Reactor For CF] Validating records

 

By default the custom validate methods extends the generated validate method.  It calls super.validate() to do the validation.  You can then do your own and add your errors into the collection.

 

Doug

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Cedric Villat
Sent: Sunday, February 26, 2006 10:51 AM
To: [email protected]
Subject: RE: [Reactor For CF] Validating records

 

Doug,

 

Yeap, that makes sense. Is the custom validate method different then the validate() method that exists in every Record? Or do I need to override this method within my Record cfc? I would obviously like to just “extend” the built-in validate method, since it has useful checks, but would like my own.

 

Cedric

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Doug Hughes
Sent: Sunday, February 26, 2006 4:39 AM
To: [email protected]
Subject: RE: [Reactor For CF] Validating records

 

Cedric,

 

When doing any sort of custom validation of a given record, I would put custom validation into the specific record.  So, in validating the length of a password, that’d go in the user records’ custom validate method. 

 

In the case where you’re validating that a specific user name has not been used, I’d also put that in the validate method.  You can easily get to the ReactorFactory via the _getReactorFactory method.  You can use that to create an instance of a UserGateway and you could call getByFields(username=’myusername’).  If any rows are returned then add an error to the validation error collection.

 

Does that help?

 

Doug

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Cedric Villat
Sent: Saturday, February 25, 2006 9:23 PM
To: [email protected]
Subject: RE: [Reactor For CF] Validating records

 

Phil,

 

Thanks. I didn’t mean to be so specific about my validation, I was just looking for an approach to validation in general. For instance, if I want to ensure that the password is at least 6 characters. Is this a check that should be put in the Record object somewhere, or in the controller? My problem with the controller, is that anywhere I set the password, I have to do my check, but if it was in a record it could be done in 1 place.

 

How are you guys doing this validation?

 

Cedric

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Phil Cruz
Sent: Saturday, February 25, 2006 9:39 AM
To: [email protected]
Subject: Re: [Reactor For CF] Validating records

 

You could do a "pre-check" in the controller but that wouldn't guarantee uniqueness because another user with that email could be inserted after that check and before you try to insert.  The only way to guarantee is to put a unique constraint in the database and catch the exception.  You can look at the Mach-II sample application to see one way to implement that.  Look at the UserListener.cfc::

    <cffunction name="createUser" access="public" returntype="void" output="false" displayname="Create User" hint="I cause a user to be created from the current event object.">
        <cfargument name="event" type="MachII.framework.Event" required="yes" displayname="Event" hint="I am the current event" />
        <cfset var user = arguments.event.getArg("user") />       
        <cfset var userData = user.getUserTO() />
        <cfset var errors = structNew() />
        <cftry>           
            <cfset variables.userService.createUser(argumentcollection=userData, dsn=variables.dsn, dbtype=variables.dbtype) />
            <cfset announceEvent("createUser.success", arguments.event.getArgs()) />
        <cfcatch type="Database">
            <cfif findNoCase("duplicate",cfcatch.detail) >
                <cfscript>
                    errors.usernameExists = "That username has been taken.";
                    user.setErrors(errors);
                    announceEvent("createUser.usernameExists", arguments.event.getArgs());
                </cfscript>               
            <cfelse>
                <cfrethrow>
            </cfif>
        </cfcatch>
        </cftry>
    </cffunction>

hth,

Phil

On 2/24/06, Cedric Villat <[EMAIL PROTECTED]> wrote:

Just a quick question about validating records. I have a UserRecord that has a Username, password, and email. Once of the requirements is that the Username must be unique. Should I check for uniqueness in a controller before I call the save() method, or should I use a Validate() method that checks for the uniqueness? If I used a Validate() method, where does it go? Is it ok to reference a UserGateway to call an Exists() function?

 

Just wondering where to do this sort of validation.

 

Cedric

-- Reactor for ColdFusion Mailing List -- [email protected] -- Archives at http://www.mail-archive.com/reactor%40doughughes.net/


-- Reactor for ColdFusion Mailing List -- [email protected] -- Archives at http://www.mail-archive.com/reactor%40doughughes.net/

-- Reactor for ColdFusion Mailing List -- [email protected] -- Archives at http://www.mail-archive.com/reactor%40doughughes.net/ -- Reactor for ColdFusion Mailing List -- [email protected] -- Archives at http://www.mail-archive.com/reactor%40doughughes.net/ -- Reactor for ColdFusion Mailing List -- [email protected] -- Archives at http://www.mail-archive.com/reactor%40doughughes.net/ -- Reactor for ColdFusion Mailing List -- [email protected] -- Archives at http://www.mail-archive.com/reactor%40doughughes.net/ -- Reactor for ColdFusion Mailing List -- [email protected] -- Archives at http://www.mail-archive.com/reactor%40doughughes.net/

Reply via email to