3 Replies Latest reply on Jan 4, 2007 10:17 AM by Newsgroup_User

    Invoke a ton of components..is there an easier way?

    Level 7
      I have a page that invokes about 12 CFC methods all at one using the
      variable 'pcode'. Each method is a different SQL statement pulling differnet
      info from the database by group.

      Rather than having to invoke each individually using the same
      invokeargument, is there a faster way?

      For example, here is a cut from the top of my page:

      <cfinvoke component="#Students#" method="ListStudents"
      returnvariable="ListStudents" argumentcollection="#Form#">
      <cfinvoke component="#Image#" method="MyImages" returnvariable="MyImages"
      argumentcollection="#Form#">>
      <cfinvoke component="#Students#" method="GetAddress"
      returnvariable="GetAddress" argumentcollection="#Form#">
      <cfinvoke component="#Students#" method="GPA" returnvariable="GPA"
      argumentcollection="#Form#">
      <cfinvoke component="#Students#" method="Education"
      returnvariable="Education" argumentcollection="#Form#">
      <cfinvoke component="#Students#" method="GetComments"
      returnvariable="GetComments" argumentcollection="#Form#">
      <cfinvoke component="#Students#" method="Academic" returnvariable="Academic"
      argumentcollection="#Form#">
      <cfinvoke component="#Students#" method="LSAT" returnvariable="LSAT"
      argumentcollection="#Form#">

      Thanks!


        • 1. Re: Invoke a ton of components..is there an easier way?
          Level 7
          You're not calling the COMPONENTS, you're calling the methods within the
          components, which are all different. So if you need all those methods
          called, then yes, you... do... have to call them.

          You could cut down the number of keystrokes and make your code more
          readable if you used CFScript instead of CFML, eg:

          <cfinvoke component="#Students#" method="ListStudents"
          returnvariable="ListStudents" argumentcollection="#Form#">
          becomes:
          ListStudents = Students.ListStudents(argumentcollection=Form);

          The other thing you could do is to to write one more method called
          doesItAll() (or something), in which you stick all that code, and
          doesItAll() takes only those few arguments needed to all those method
          calls, and returns one struct with all the results in it:

          stResult = Students.doesItAll(argumentCollection=Form);


          <cffunction name="doesItAll" returntype="struct" output="false">
          <cfscript>
          var stReturn = structNew(argumentcollection=arguments);
          stReturn.ListStudents = ListStudents(argumentcollection=arguments);
          stReturn.GetAddress = GetAddress(argumentcollection=arguments);
          stReturn.GPA = GPA(argumentcollection=arguments);
          stReturn.Education = Education(argumentcollection=arguments);
          stReturn.GetComments = GetComments(argumentcollection=arguments);
          stReturn.Academic = Academic(argumentcollection=arguments);
          stReturn.LSAT = LSAT(argumentcollection=arguments);

          return stReturn;
          </cfscript>
          </cffunction>

          (note: this omits the call to the "image" component, which would still need
          to be done separately)

          --
          Adam
          • 2. Re: Invoke a ton of components..is there an easier way?
            Dan Bracuk Level 5
            <cfobject> or createobject would entail less code. Plus, you could write an init() method in your students.cfc that processes the form variables and makes cfc variables available to all the functions contained therein.
            • 3. Re: Invoke a ton of components..is there an easier way?
              Level 7
              I will look into creating something like a doesItAll. I do use the cfobject
              I just didn't include that in the page cut.

              Thanks guys.