Stacy,

In the "setInstanceMemento()" function you have the following line:

   <cfset variables.contacts[x].setMemento(arguments.memento.contacts[x] ) )
/>

At some point "variables.contacts[x]" has to be set to an instance of
mysite.model.Contact.  Otherwise, it will not know what to do with the
"setMemento()" method call. So, I guess that the answer to your question is
yes--you must be maintaining an array of Contact objects in your variables
(variables.contacts) scope.

The simplest way to do this might be to simply create a Contact object for
each instance indicated in the memento:

   <cfset contact = CreateObject("component", "mysite.model.Contact")>
   <cfset contact.setMemento(arguments.memento.contacts[x])>
   <cfset variables.contacts[x] = contact>

You could also create a factory method that returns an instance of Contact:

   <cffunction name="newContact" returntype="mysite.model.Contact"
access="private">
      <cfreturn CreateObject("component", "mysite.model.Contact")/>
   </cffunction>

Then change the the three previous lines in "setInstanceMemento()" to:

   <cfset variables.contacts[x] = newContact()>
   <cfset variables.contacts[x].setMemento(arguments.memento.contacts[x]))>

Anyhow, I have been tossing this same question around in my mind for a
little while myself.  This is one solution I have come up with.   

Paul Kenney
WebMaster, CorporateWarriors.com
916-663-1963


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Stacy Young
Sent: Saturday, December 20, 2003 6:45 PM
To: [EMAIL PROTECTED]
Subject: RE: [CFCDev] memento and composition (w/ arrays)



This may be an obvious question but...should I be maintaining an array
of Contact objects in variables scope as well? (code snippet below)

Muchos gracias,

Stace

<cfcomponent displayname="Affiliate Object" output="false">


        <cffunction name="init" output="false" access="public"
returntype="Affiliate">
                <cfargument name="data" type="struct"
default="#structNew()#" />
                <cfset variables.instance = arguments.data />
                <!--- Array for Contact Objects --->
                <cfset variables.contacts = ArrayNew(1) />
                <cfset variables.requiredFields = "" />
                <cfset variables.missingFields = "" />
                <cfset variables.invalidFields = "" />
                <cfreturn this />
        </cffunction>
        

        <cffunction name="addContact" access="public" returntype="void"
output="false">
                <cfargument name="contact" type="mysite.model.Contact"
required="yes" />
                <cfset ArrayAppend( variables.contacts,
arguments.contact ) />
        </cffunction>
        

        <cffunction name="getInstanceMemento" access="public"
returntype="struct" output="false">
                <cfset var x = "" />
                <cfset variables.instance.contacts = ArrayNew(1) />
                <cfloop index="x" from="1" to="#ArrayLen(
variables.contacts )#">
                        <cfset ArrayAppend( variables.instance.contacts,
variables.contacts[x].getMemento() ) />
                </cfloop>
                <cfreturn variables.instance />
        </cffunction>
        

        <cffunction name="setInstanceMemento" access="public"
returntype="Affiliate" output="false">
                <cfargument name="memento" type="struct" required="yes"
/>
                <cfset var x = "" />
                <cfset variables.instance = arguments.memento />
                <cfloop index="x" from="1" to="#ArrayLen(
variables.instance.contacts )#">
                        <cfset variables.contacts[x].setMemento(
arguments.memento.contacts[x] ) ) />
                </cfloop>
                <cfreturn this />
        </cffunction>

</cfcomponent>




-----Original Message-----
From: Sean A Corfield [mailto:[EMAIL PROTECTED] 
Sent: Saturday, December 20, 2003 8:01 PM
To: [EMAIL PROTECTED]
Subject: Re: [CFCDev] memento and composition (w/ arrays)

On Dec 20, 2003, at 4:54 PM, Stacy Young wrote:
> I've got an Affiliate.cfc which contains an array of Contact.cfc
> objects. I'm guessing I could just store an array of contact mementos 
> in
> the struct?

Yup

Sean A Corfield -- http://www.corfield.org/blog/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

----------------------------------------------------------
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]



AVIS IMPORTANT:
------------------------------- 
Les informations contenues dans le present document et ses pieces jointes
sont strictement confidentielles et reservees a l'usage de la (des)
personne(s) a qui il est adresse. Si vous n'etes pas le destinataire, soyez
avise que toute divulgation, distribution, copie, ou autre utilisation de
ces informations est strictement prohibee. Si vous avez recu ce document par
erreur, veuillez s'il vous plait communiquer immediatement avec l'expediteur
et detruire ce document sans en faire de copie sous quelque forme.

WARNING:
-------------------------------
The information contained in this document and attachments is confidential
and intended only for the person(s) named above. If you are not the intended
recipient you are hereby notified that any disclosure, copying,
distribution, or any other use of the information is strictly prohibited. If
you have received this document by mistake, please notify the sender
immediately and destroy this document and attachments without making any
copy of any kind.

----------------------------------------------------------
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]

Reply via email to