no problem.
when CF works with complex variables (structures,
arrays etc) doing <cfset myStruct2=myStruct>
will only create a new reference to the same space in
memory, not a totally new variable.
(so both variables will then reference to the same space in
memory)
try this code to see that:
<cfset myStruct=StructNew()>
<cfset myStruct.test="something">
<cfdump var="#myStruct#">
<cfset myStruct2=myStruct>
<cfset myStruct2.test="something else">
<cfdump var="#myStruct#">
<cfset myStruct.test="something">
<cfdump var="#myStruct#">
<cfset myStruct2=myStruct>
<cfset myStruct2.test="something else">
<cfdump var="#myStruct#">
when
you did <cfset session.formResult[....]=form>, your session variable
actually referenced the space in memory
where
cold fusion keeps FORM structure, so on the next submit, this space in memory
was overwritten, as well as
your
session variable content. To avoid this you need to copy (or, better
to say, clone) the variable content using Duplicate
function.
It is
different for simple variables (strings, numeric, boolean etc) - that's why
WDDX approach worked.
From: Sam Westlake [mailto:[EMAIL PROTECTED]
Sent: 13 April 2004 16:21
To: [EMAIL PROTECTED]
Subject: RE: [ cf-dev ] Session Variables
That's fixed it !! - Thanks Albert.
So why does this work?
Sam
From: Albert Popkov [mailto:[EMAIL PROTECTED]
Sent: 13 April 2004 15:55
To: [EMAIL PROTECTED]
Subject: RE: [ cf-dev ] Session Variables
you can try
<cfset session.formResult["#FORM.type#"] =
Duplicate(FORM)>
this will actually
create a new variable (without duplicate it should only create a reference to
the same structure,
which is changed
when the next form is submitted).
StructCopy may also
be useful. There were some bugs reported with both Duplicate and StructCopy -
such as
some problems
working with nested structures - the best is to check macromedia.com for fixes
etc.
From: Sam Westlake [mailto:[EMAIL PROTECTED]
Sent: 13 April 2004 14:05
To: [EMAIL PROTECTED]
Subject: [ cf-dev ] Session Variables
I am trying to
persist session variables from one page to the next.
This is the
application.cfm file:
<cfapplication
name="game001"
clientmanagement="Yes"
sessionmanagement="Yes"
sessiontimeout="#CreateTimeSpan(0,0,10,0)#"
applicationtimeout="#CreateTimeSpan(0,0,10,0)#">
clientmanagement="Yes"
sessionmanagement="Yes"
sessiontimeout="#CreateTimeSpan(0,0,10,0)#"
applicationtimeout="#CreateTimeSpan(0,0,10,0)#">
This is a template
that runs at the beginning of each page (six pages - one for each formResult
structure) to instatiate empty structure objects in the session
scope:
<cfif
isDefined("session.formResult") IS FALSE>
<!--- lock
the session variable to stop race conditions --->
<cflock name="game#SESSION.SessionID#"
type="exclusive"
timeout="3">
<!--- instantite empty structures for each section --->
<cfset session.formResult = StructNew()>
<cfset session.formResult.planning = StructNew()>
<cfset session.formResult.buying = StructNew()>
<cfset session.formResult.preparing = StructNew()>
<cfset session.formResult.marketing = StructNew()>
<cfset session.formResult.tenants = StructNew()>
<cfset session.formResult.selling = StructNew()>
</cflock>
</cfif>
<cflock name="game#SESSION.SessionID#"
type="exclusive"
timeout="3">
<!--- instantite empty structures for each section --->
<cfset session.formResult = StructNew()>
<cfset session.formResult.planning = StructNew()>
<cfset session.formResult.buying = StructNew()>
<cfset session.formResult.preparing = StructNew()>
<cfset session.formResult.marketing = StructNew()>
<cfset session.formResult.tenants = StructNew()>
<cfset session.formResult.selling = StructNew()>
</cflock>
</cfif>
This is a template
that runs after every form submission ("type" is a hidden field in the form and
has a value of one of the above structures, e.g., planning, buying, preparing,
etc) - it copies the form results to the appropriate
structure
<cfif
isDefined("FORM.type")>
<cfset session.formResult["#FORM.type#"] = FORM>
</cfif>
<cfset session.formResult["#FORM.type#"] = FORM>
</cfif>
After running this
last template then I cfdump the session scope. Each time it shows the form
elements from the current form submission succesfully added to the appropriate
structure in the session scope. But after submitting the next form then any form
variables from the previous submission are not found - only the empty structure
and the current variables each time
Anyone know why this
is happening?
Thanks in
advance,
Sam
Westlake
