[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Createobject - cfinvoke

Posted on 2012-03-22
7
Medium Priority
?
342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1800 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
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 …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

650 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