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"
      <cfinvoke component="#Students#" method="GetAddress"
      returnvariable="GetAddress" argumentcollection="#Form#">
      <cfinvoke component="#Students#" method="GPA" returnvariable="GPA"
      <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"
      <cfinvoke component="#Students#" method="LSAT" returnvariable="LSAT"


        • 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#">
          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">
          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;

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

          • 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.