Solved

Createobject - cfinvoke

Posted on 2012-03-22
7
334 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 16

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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CFC Lookup - When Not Found 5 75
Align a <div> to a table row 3 83
coldfusion cfloop help 6 33
Coldfusion / Railo 4 -  datetimeFormat problem 3 31
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 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