I am building an application that is for entering expenses. I am using
one template for accepting posted information. This template calls
another template to place this information into a set of nested
structures. Then another template is called to validate the
information. Then I copy the original structure using StructCopy(), and
I remove the invalid keys (using StructDelete()) from my copy. My
problem is that the invalid keys are being removed from both the copy
and the original structures. This is not how the behavior is described
in the Cold Fusion manual.
Any ideas?
Code:
This is the cold that calls the converter:
-------------------------------------------------------------------------------
<!--- convert the form values to something useful --->
<cfmodule template="apiExpenseConverter.cfm"
stInput="request"
return="request.stExpenseIn">
<!--- I have placed all the time information into a structure --->
--------------------------------------------------------------------------------
Converter Code:
<cfparam name="attributes.stInput">
<cfparam name="attributes.return" default="stExpense">
<cfscript>
variables.expensePtr = StructNew();
if ( NOT isStruct(attributes.stInput)) {
evaluate("variables.expensePtr = #attributes.stInput#");
}
else {
variables.expensePtr = attributes.stInput;
}
//get all the keys from the expensePtr
variables.arKeys = StructKeyArray(variables.expensePtr);
//create a structure for holding the converted expenses
variables.stExpense = StructNew();
/*
I only care about certain keys. I will use a regular Expression to
find
extract this information.
ExpenseDetail:
detailDt_\d+_\d+
description_\d+_\d+
amount_\d+_\d+
expenseTypeOID_\d+_\d+
ExpenseMaster:
projectDesc_\d+
wkEndingDt_\d+
*/
for ( variables.i = ArrayLen(variables.arKeys); variables.i GT 0;
variables.i = variables.i -1) {
variables.stTmp =
REFindNoCase("(detaildt|description|amount|expensetypeoid|projectdesc|wkendingdt)_(n?[[:digit:]]+)(_(n?[[:digit:]]+))?",
variables.arKeys[variables.i], 1, TRUE);
if ( variables.stTmp.len[1] ) {
variables.strMasterOID = Mid(variables.arKeys[variables.i],
variables.stTmp.pos[3], variables.stTmp.len[3]);
if (NOT StructKeyExists(variables.stExpense, variables.strMasterOID)
) {
StructInsert(variables.stExpense, variables.strMasterOID,
StructNew());
StructInsert(variables.stExpense[variables.strMasterOID],
"DETAILS", StructNew());
}
//look at the type and figure out what to do
variables.strKey = mid(variables.arKeys[variables.i],
variables.stTmp.pos[2], variables.stTmp.len[2]);
if ( ArrayLen(variables.stTmp.len) EQ 5){ // this is a detail
variables.strDetailOID = Mid(variables.arKeys[variables.i],
variables.stTmp.pos[5], variables.stTmp.len[5]);
if (NOT
StructKeyExists(variables.stExpense[variables.strMasterOID]["DETAILS"],
variables.strDetailOID) )
StructInsert(variables.stExpense[variables.strMasterOID]["DETAILS"],
variables.strDetailOID, StructNew());
StructInsert(variables.stExpense[variables.strMasterOID]["DETAILS"][variables.strDetailOID],
variables.strKey, request[variables.arKeys[variables.i]]);
}
else { //this is a master
StructInsert(variables.stExpense[variables.strMasterOID],
variables.strKey, request[variables.arKeys[variables.i]]);
}
}
}
evaluate("caller." & attributes.return & " = StructNew()");
evaluate("caller." & attributes.return & " =
StructCopy(variables.stExpense)");
</cfscript>
---------------------------------------------------------------------------------
Back to the Calling template:
<!--- verify the expense report --->
<cfmodule name="cd.verifyexpensereport"
expensereport="request.stExpenseIn" return="request.stReturn">
Original1:
<cfmodule name="cd.objectdump" object="#request.stExpenseIn#">
<cfset stValid = StructCopy(request["stExpenseIn"])>
<cfset arinvalid = StructFindValue(request.stReturn, 'invalid', 'all')>
<cfloop from="1" to="#arraylen(arInvalid)#" index="i">
<cfset variables.stRE =
REFindNoCase("\.(n[[:digit:]]+|[[:digit:]]+)\.(details)\.(n[[:digit:]]+|[[:digit:]]+)\.([description|detaildt|expensetypeoid|amount])",
arinvalid[i]["path"], 1, true )>
<cfset tmp =
structdelete(variables.stValid[mid(variables.arinvalid[variables.i]["path"],
variables.stre["pos"][2],
variables.stre["len"][2])]
[mid(variables.arinvalid[variables.i]["path"],
variables.stre["pos"][3],
variables.stre["len"][3])],
mid(variables.arinvalid[variables.i]["path"],
variables.stre["pos"][4],
variables.stre["len"][4]))>
</cfloop>
--
Josh Meekhof
Software Engineer
Techniki Informatica / Network Staffing Services, Inc.
(972) 233-1525
-------------------------------------------------------------------------
This email server is running an evaluation copy of the MailShield anti-
spam software. Please contact your email administrator if you have any
questions about this message. MailShield product info: www.mailshield.com
-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org