I'd suggest you create a basic error object with the methods you've
outlined above, then cache it in the session scope.
Then, when you need an error object, it's easy enough to give your
other objects a getErrorObject() method and do something like the
following:
<cffunction name="someMethod">
<cftry>
<cfthrow message="some error message">
<cfcatch>
<cfset saveErrors(cferror)>
</cfcatch>
<cftry>
And later, in in the same object:
<cffunction name="saveErrors">
<cfargument name="errors" type="struct" required="true" />
<cfscript>
var errorObject = getErrorObject();
errorObject.setError(arguments["errors"]);
return errorObject;
</cfscript>
</cffunction>
Obviously, you'd need to supply the methods saveErrors,
getErrorObject, setErrorObject, etc., in your various classes and the
methods you've outlined above in your error object... plus I'd suggest
a method such as hasErrors that checks the error object's variables
scope for the struct containing the errors... and I wouldn't use a
placeholder, leave it empty or uninitialized until you need to create
an error. That leaves you able to use hasErrors() to return a boolean
to your other objects if "not structKeyExists(variables,'errors')"
when you check... i.e. <cfif getErrorObject().hasErrors()>...do
stuff...</cfif> from within a DAO.
I'm not sure that what I wrote will make any sense to anyone but me...
so let me know if it doesn't and I can try again. ;)
Laterz,
J
On Sun, 13 Mar 2005 21:47:50 -0800, Daniel Short <[EMAIL PROTECTED]> wrote:
> Hi everyone,
>
> I'm trying to figure out the "best" way to handle user validation errors
> inside my CFCs. I've written CFCs previously that used a returned struct
> directly from the CFC with the errors for the current method. But I'm
> thinking it might be a good idea to create a global "Error Handler" cfc that
> would have just a few methods, like:
>
> setError("fieldname", "ErrorTitle", "ErrorString")
> getError("fieldname")
> getErrors() - Returns full struct of errors
>
> Then errors inside the object would be managed by a structure. My problem
> with this is how do I reference this global error object? Do I pass it in
> for each DAO method I use? So for example, would I do something like this?:
>
> <cfset ErrObject = CreateObject("component", "cfc.ErrorHanderl").init()>
> <cfset User = CreateObject("component", "cfc.User").init()>
> <!---
> Do some sets on the user
> --->
> <cfset User.Update(ErrorObject)>
>
> I'm not quite sure if I'm taking the right approach here and just asking for
> trouble, since all of my objects will have to know about the error handlers
> methods. I think this is valid composition but would somewhat break the
> encapsulation of my objects.
>
> Thanks in advance,
>
> Dan
--
Continuum Media Group LLC
Burnsville, MN 55337
http://www.web-relevant.com
http://cfobjective.neo.servequake.com
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
[email protected] with the words 'unsubscribe cfcdev' as the subject of the
email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.com).
An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]