I am no expert in Object Oriented Programming, and I'm pretty sure I am
loosing the plot somewhere with the following cfc, I would really appreciate
some expert input from someone (Sean where art thou)..
I believe I need to lock any access to the object as its in the server
scope, not sure yet whether it gives better performance creating the object
only once in the server and lock access to it, or recreate the object every
time and not having to lock access to it, I believe its the first one.
I think I am losing the plot when we get to
request.result.objError.fnConstruct( request.result );
request.result.objError.fnDisplay( request.result );
But I can't really tell you why, but I'm pretty sure its not a good thing
having to pass itself back with request.result
Hope someone's still awake..
****************************
test.cfm
<cfscript>
// this will eventually only be set once in the server scope
server.objProcess = createObject("component", "process");
</cfscript>
<cflock timeout="10"
throwontimeout="yes"
type="exclusive"
scope="server">
<cfscript>
request.result = server.objProcess.fnExecute( "this string means nothing"
);
request.result.objError.fnConstruct( request.result );
request.result.objError.fnDisplay( request.result );
</cfscript>
</cflock>
<cfdump var="#request.result#">
****************************
process.cfc
<cfcomponent>
<cfscript>
this.result = structNew();
message = structNew();
structInsert(message, "isDisplayed", false);
structInsert(message, "isMessage", false);
structInsert(message, "myArray", arrayNew(1));
structInsert(message, "myString", "");
structInsert(this.result, "message", message);
error = structNew();
structInsert(error, "isDisplayed", false);
structInsert(error, "isError", false);
structInsert(error, "myArray", arrayNew(1));
structInsert(error, "myString", "");
structInsert(this.result, "error", error);
structInsert(this.result, "objError", createObject("component", "error"));
</cfscript>
<cffunction access="public"
name="fnExecute"
output="false"
returntype="struct">
<!--- I do nothing --->
<cfargument name="myArgument"
type="string"
required="true">
<cftry>
<!--- I error for test purposes --->
<cfoutput>#ttt#</cfoutput>
<cfcatch type="any">
<!--- Update isError to true --->
<cfset structUpdate(this.result.error, "isError", true)>
<!--- Append the error message --->
<cfset this.result.objError.fnAppend( this.result, 'this is the message
' )>
</cfcatch>
</cftry>
<cfreturn this.result>
</cffunction>
</cfcomponent>
****************************
error.cfc
<cfcomponent displayname="Error"
hint="I work with errors">
<!--- Function --->
<cffunction access="public"
name="fnAppend"
output="false"
returntype="any"
displayname="Error Append"
hint="I append an error message to an array">
<cfargument name="result"
type="struct"
required="true"
displayname="Result Structure"
hint="I am the Result Structure">
<cfargument name="errorMessage"
type="string"
required="true"
default="There was an error"
displayname="Error Message"
hint="I am the error message to append">
<!--- Append the error and return the array that contains the errors --->
<cfreturn arrayAppend(arguments.result.error.myArray,
arguments.errorMessage)>
</cffunction>
<!--- Function --->
<cffunction access="public"
name="fnConstruct"
output="false"
returntype="struct"
displayname="Error Construct"
hint="I construct error messages">
<cfargument name="result"
type="struct"
required="true"
displayname="Result Structure"
hint="I am the Result Structure">
<!--- Construct the error, if any --->
<cfif arguments.result.error.isError>
<cfset string = "<p>There are some errors, please correct;</p><ul>">
<cfloop from="1" to="#arrayLen(arguments.result.error.myArray)#"
index="i">
<cfset string = string & "<li>#arguments.result.error.myArray[ i
]#</li>">
</cfloop>
<cfset string = string & "</ul>">
<!--- Update the result structure with the error string --->
<cfset structUpdate(arguments.result.error, "myString", string)>
</cfif>
<cfreturn arguments.result>
</cffunction>
<!--- Function --->
<cffunction access="public"
name="fnDisplay"
output="true"
returntype="any"
displayname="Error Display"
hint="I display error messages">
<cfargument name="result"
type="struct"
required="true"
displayname="Result Structure"
hint="I am the structure that contains the result">
<!--- Update the displayed property --->
<cfscript>
structUpdate(arguments.result.error, "isDisplayed", true);
</cfscript>
<cfreturn arguments.result>
</cffunction>
<cffunction access="public"
name="fnClear"
output="false"
returntype="any"
displayname="Error Clear"
hint="I clear error messages">
<cfargument name="result"
type="struct"
required="true"
displayname="Result Structure"
hint="I am the structure that contains the result">
<!--- Clear the array --->
<cfreturn arrayClear(arguments.result.error.myArray)>
</cffunction>
</cfcomponent>
Taco Fleur
Tell me and I will forget
Show me and I will remember
Teach me and I will learn
[Todays Threads]
[This Message]
[Subscription]
[Fast Unsubscribe]
[User Settings]
[Donations and Support]