dynamic function call puzzle

2005-10-12 Thread Paul
My read function returns, predictably, a query object with a single row
containing all the columns needed to populate a bean.  It bothers me that to
use the bean I then have to write a code block full of set statements -
mybean.setVariable(queryname.column) - for every property of the bean.

 

So I'm trying to write a function that takes the result of my read
function and automatically sets the bean values.  I've been able to populate
a struct dynamically, but not without using evaluate(), and I can't call my
bean's set functions at all.  How can I improve on the following code?

 

cfquery name=q datasource=#getDSN()#

select * 

from TEMPLATES

where TEMPLATE_ID = cfqueryparam value=2
cfsqltype=cf_sql_integer

/cfquery

 

cfset o=createObject(component,com.redweb.Template).init()

cfoutput query=q

cfscript

colArray=listToArray(q.columnlist);

 

//test struct to see if I can get that far.

s=structNew();

for (x=1; x LTE arrayLen(colArray); x=x+1) {

//this test is ugly but it works

s.#colArray[x]#=evaluate(colArray[x]);

 

//this is not valid but it is
essentially what I want to do...

 
o.set#colArray[x]#(evaluate(colArray[x]));

}

/cfscript

/cfoutput

 

cfdump var=#s#

cfdump var=#o.getSnapshot()#



~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:220808
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


Re: dynamic function call puzzle

2005-10-12 Thread Ryan Guill
The following code does something similar to what you want to do, but it 
outputs it to the screen, but if you look youll see what it is you need I think:

cfset variables.arResultsHeaders = ListToArray(variables.q.columnlist) /
cfoutput
table align=left id=queryResults
tr
th
Row
/th
cfloop from=1 
to=#arrayLen(variables.arResultsHeaders)# index=i
th
#variables.arResultsHeaders[i]#
/th
/cfloop
/tr
cfloop from=1 to=#variables.q.recordCount# index=k
tr
th
#NumberFormat(k,)#
/th
cfloop from=1 
to=#arrayLen(variables.arResultsHeaders)# index=j
td

#variables.q[#variables.arResultsHeaders[j]#][k]#
/td
/cfloop
/tr
/cfloop

/table
/cfoutput

~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:220812
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


RE: dynamic function call puzzle

2005-10-12 Thread Kerry
heres what i do when I need to dynamically call functions - make all your
beans inherit this:

cffunction name=runFunction
cfargument name=functionname type=string required=yes
cfargument name=args type=struct required=no
default=#structnew()#
cfset var retval = 
cfinvoke component=#this#

method=#arguments.functionname#

argumentCollection=#arguments.args#
returnvariable=retval
cfreturn retval
/cffunction


Then you can:

o.runfunction(setcolArray[x],q[colArray[x]]);

-Original Message-
From: Paul [mailto:[EMAIL PROTECTED]
Sent: 12 October 2005 16:47
To: CF-Talk
Subject: dynamic function call puzzle


My read function returns, predictably, a query object with a single row
containing all the columns needed to populate a bean.  It bothers me that to
use the bean I then have to write a code block full of set statements -
mybean.setVariable(queryname.column) - for every property of the bean.



So I'm trying to write a function that takes the result of my read
function and automatically sets the bean values.  I've been able to populate
a struct dynamically, but not without using evaluate(), and I can't call my
bean's set functions at all.  How can I improve on the following code?



cfquery name=q datasource=#getDSN()#

select *

from TEMPLATES

where TEMPLATE_ID = cfqueryparam value=2
cfsqltype=cf_sql_integer

/cfquery



cfset o=createObject(component,com.redweb.Template).init()

cfoutput query=q

cfscript

colArray=listToArray(q.columnlist);



//test struct to see if I can get that far.

s=structNew();

for (x=1; x LTE arrayLen(colArray); x=x+1) {

//this test is ugly but it works

s.#colArray[x]#=evaluate(colArray[x]);



//this is not valid but it is
essentially what I want to do...


o.set#colArray[x]#(evaluate(colArray[x]));

}

/cfscript

/cfoutput



cfdump var=#s#

cfdump var=#o.getSnapshot()#





~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:220813
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


RE: dynamic function call puzzle

2005-10-12 Thread Kerry
oops, with that flavour of the function you will need:

args = structnew();
args[colArray[x]] = q[colArray[x]][q.currentrow];
o.runfunction(setcolArray[x],args);


-Original Message-
From: Kerry [mailto:[EMAIL PROTECTED]
Sent: 12 October 2005 16:57
To: CF-Talk
Subject: RE: dynamic function call puzzle


heres what i do when I need to dynamically call functions - make all your
beans inherit this:

cffunction name=runFunction
cfargument name=functionname type=string required=yes
cfargument name=args type=struct required=no
default=#structnew()#
cfset var retval = 
cfinvoke component=#this#

method=#arguments.functionname#

argumentCollection=#arguments.args#
returnvariable=retval
cfreturn retval
/cffunction


Then you can:



-Original Message-
From: Paul [mailto:[EMAIL PROTECTED]
Sent: 12 October 2005 16:47
To: CF-Talk
Subject: dynamic function call puzzle


My read function returns, predictably, a query object with a single row
containing all the columns needed to populate a bean.  It bothers me that to
use the bean I then have to write a code block full of set statements -
mybean.setVariable(queryname.column) - for every property of the bean.



So I'm trying to write a function that takes the result of my read
function and automatically sets the bean values.  I've been able to populate
a struct dynamically, but not without using evaluate(), and I can't call my
bean's set functions at all.  How can I improve on the following code?



cfquery name=q datasource=#getDSN()#

select *

from TEMPLATES

where TEMPLATE_ID = cfqueryparam value=2
cfsqltype=cf_sql_integer

/cfquery



cfset o=createObject(component,com.redweb.Template).init()

cfoutput query=q

cfscript

colArray=listToArray(q.columnlist);



//test struct to see if I can get that far.

s=structNew();

for (x=1; x LTE arrayLen(colArray); x=x+1) {

//this test is ugly but it works

s.#colArray[x]#=evaluate(colArray[x]);



//this is not valid but it is
essentially what I want to do...


o.set#colArray[x]#(evaluate(colArray[x]));

}

/cfscript

/cfoutput



cfdump var=#s#

cfdump var=#o.getSnapshot()#







~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:220814
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


RE: dynamic function call puzzle

2005-10-12 Thread Paul
Wow, this is great, really expanding my horizons here...

So in the inherited function CF throws this error: Variable RETVAL is
undefined.

I do have the following as you sent; CF refers to the CFINVOKE line number
in the error message.  Maybe I need a deeper understanding to figure out
what I may have done differently to cause the error...  (Something about my
Setters perhaps?)

cfset var retval = 
cfinvoke component=#this# 
method=#arguments.functionname#
argumentCollection=#arguments.args# 
returnvariable=retval
cfreturn retval 

-Original Message-
From: Kerry [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, October 12, 2005 10:04 AM
To: CF-Talk
Subject: RE: dynamic function call puzzle

oops, with that flavour of the function you will need:

args = structnew();
args[colArray[x]] = q[colArray[x]][q.currentrow];
o.runfunction(setcolArray[x],args);


~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:220817
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


RE: dynamic function call puzzle

2005-10-12 Thread Kerry
probly because your sets dont return anything?

1) take the return out of the runfunction:

cffunction name=runFunction
cfargument name=functionname type=string required=yes
cfargument name=args type=struct required=no
default=#structnew()#
cfset var retval = 
cfinvoke component=#this#

method=#arguments.functionname#

argumentCollection=#arguments.args#
returnvariable=retval

/cffunction

OR

2) check it exists

cffunction name=runFunction
cfargument name=functionname type=string required=yes
cfargument name=args type=struct required=no
default=#structnew()#
cfset var retval = structnew()
cfinvoke component=#this#

method=#arguments.functionname#

argumentCollection=#arguments.args#

returnvariable=retval.result

cfif structkeyexists(retval,result)
cfreturn retval
/cfif

/cffunction

-Original Message-
From: Paul [mailto:[EMAIL PROTECTED]
Sent: 12 October 2005 17:25
To: CF-Talk
Subject: RE: dynamic function call puzzle


Wow, this is great, really expanding my horizons here...

So in the inherited function CF throws this error: Variable RETVAL is
undefined.

I do have the following as you sent; CF refers to the CFINVOKE line number
in the error message.  Maybe I need a deeper understanding to figure out
what I may have done differently to cause the error...  (Something about my
Setters perhaps?)

cfset var retval = 
cfinvoke component=#this#
method=#arguments.functionname#
argumentCollection=#arguments.args#
returnvariable=retval
cfreturn retval

-Original Message-
From: Kerry [mailto:[EMAIL PROTECTED]
Sent: Wednesday, October 12, 2005 10:04 AM
To: CF-Talk
Subject: RE: dynamic function call puzzle

oops, with that flavour of the function you will need:

args = structnew();
args[colArray[x]] = q[colArray[x]][q.currentrow];
o.runfunction(setcolArray[x],args);




~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:220818
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


RE: dynamic function call puzzle

2005-10-12 Thread Kerry
OR

3) Customise it entirely for your beans, e.g.

cffunction name=runSetter
cfargument name=property type=string required=yes
cfargument name=value type=string required=no
default=

cfinvoke component=#this#

method=SET#arguments.property#

value=#arguments.value#


/cffunction



-Original Message-
From: Paul [mailto:[EMAIL PROTECTED]
Sent: 12 October 2005 17:25
To: CF-Talk
Subject: RE: dynamic function call puzzle


Wow, this is great, really expanding my horizons here...

So in the inherited function CF throws this error: Variable RETVAL is
undefined.

I do have the following as you sent; CF refers to the CFINVOKE line number
in the error message.  Maybe I need a deeper understanding to figure out
what I may have done differently to cause the error...  (Something about my
Setters perhaps?)

cfset var retval = 
cfinvoke component=#this#
method=#arguments.functionname#
argumentCollection=#arguments.args#
returnvariable=retval
cfreturn retval

-Original Message-
From: Kerry [mailto:[EMAIL PROTECTED]
Sent: Wednesday, October 12, 2005 10:04 AM
To: CF-Talk
Subject: RE: dynamic function call puzzle

oops, with that flavour of the function you will need:

args = structnew();
args[colArray[x]] = q[colArray[x]][q.currentrow];
o.runfunction(setcolArray[x],args);




~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:220819
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54