Solved

Createobject - cfinvoke

Posted on 2012-03-22
7
332 Views
Last Modified: 2012-03-22
Hello experts.
I need help to replace the following createobject with cfinvoke.
cfm
<cfset objsheduletask = createobject("component","com.scheduletasks").init(request.dsn)/>
<cfset objsheduletask.fsendundelivered(request.homeurl)/>

cfc
   <cffunction name="init" access="public" output="false" returntype="any">
        <cfargument name="dsn" type="string" required="true">
        <cfset variables.dsn = arguments.dsn>
        <cfreturn this>
   </cffunction>
   <cffunction name="fsendundelivered" returntype="boolean" access="public">
     <cfargument name="homeurl" type="string" required="yes">
 <cfquery name="....." datasource="#variables.dsn#">
.....
     
     <cfreturn true>
   </cffunction>

I could use:
cfm.
<cfinvoke component="com.scheduletasks" method="fsendundelivered">
 <cfinvokeargument name="homeurl" value="#request.homeurl#" >
</cfinvoke>
cfc
<cffunction name="fsendundelivered" returntype="boolean" access="public">
     <cfargument name="homeurl" type="string" required="yes">
      <cfquery name="....." datasource="#request.dsn#">
      .......
     <cfreturn true>
   </cffunction>
Is this correct?
Is there any better way?
0
Comment
Question by:Panos
7 Comments
 
LVL 15

Expert Comment

by:Gurpreet Singh Randhawa
ID: 37752056
here u should should

 <cfinvokeargument name="homeurl" value="#request.homeurl#" >

rest i m not sure what u are asking abt
0
 
LVL 2

Author Comment

by:Panos
ID: 37752078
Hi myselfrandhawa
I did correct this the same time you posted your comment.


Using the createobject i use the init function to set the dsn.
Using cfinvoke i have to delete the init function and use the request.dsn value.

I'm asking if i do this right
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 450 total points
ID: 37752282
Nothing technically wrong with the way you have it. But using a #request# variable makes the cfc slightly less modular.

Is there any better way?

If you're sure the component is stateless, and not tied to a specific session, yeah. Whichever you're using it's better to create stateless components once (in OnApplicationStart). Then store them in your application scope.  Using your original init() method:

       <cfinvoke component="com.scheduletasks" method="init"
                   dsn="#request.dsn" returnVariable="theObject" />
        <cfset application.scheduleTasks = theObject >

Then when you need to call one of the functions use:

    <cfinvoke component="#application.scheduleTasks#" method="fsendundelivered">
          <cfinvokeargument name="homeurl" value="#request.homeurl#" >
     </cfinvoke>

Just make sure ALL of your function variables are properly var scoped. Otherwise you'll have threading problems.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 50 total points
ID: 37752347
I'm curious why the change from createObject to cfinvoke.  To me createobject is a cleaner, more intuitive style and easier to assign to an application scope


<cfset application.sheduleTasks = createobject("component","com.scheduletasks").init(request.dsn)/>

Why would you want to change away from it?  (Other than a person preference to cfinvoke?)
0
 
LVL 52

Expert Comment

by:_agx_
ID: 37752406
Possible hosting restriction? Though my preference is createObject too..
0
 
LVL 2

Author Comment

by:Panos
ID: 37752471
Hi agx and gdemaria
Thank you for your posts.
Agx is right . There is a hosting restriction when i use createobject edit a scheduletask.
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 37752581
Thank you
regards panos
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now