6 Replies Latest reply on Feb 21, 2008 6:11 AM by cfchick12

    Accesing Form and Request variables in cfc

    cfchick12
      Hi,
      I have a cfc published as a webservice. I have insert statements in the cfcs
      which uses form and request variables. When I invoke the component, I get an error form
      variable is not defined. Am I missing something?.

      Thanks all for your time.

        • 1. Re: Accesing Form and Request variables in cfc
          CF_Oracle Level 1
          Did you put access="remote"? Please put your code of cfc and calling page to review for variable name and other things to better help you.
          • 2. Re: Accesing Form and Request variables in cfc
            Dan Bracuk Level 5
            Your are submitting your form to the page that invokes that cfc. The cfc knows of no such form. Anything it needs, you must pass to it as an argument.
            • 3. Re: Accesing Form and Request variables in cfc
              Level 7
              Dan Bracuk wrote:
              > Your are submitting your form to the page that invokes that cfc. The cfc knows of no such form. Anything it needs, you must pass to it as an argument.

              And if you use a cfc method as the action of a form, that is done
              automatically. All the form fields become arguments of the method and
              you would access them as such.

              I.E. form.myField becomes arguments.myField inside the CFC method.

              • 4. Re: Accesing Form and Request variables in cfc
                cfchick12 Level 1
                Hi,
                Thank you for the response, I guess I can't use form or request variables. I think I have to parse and return response back as a return value and do my inserts. Below is my code, the variables are defined in the page where I am invoking the webservice.

                <!---Function Invoked--->
                <cfinvoke
                webservice="ws_ReviewSheet"
                method="ReviewWS"
                returnvariable="response">
                </cfinvoke>

                <!---cfc Code--->
                <cfcomponent>
                <cffunction name="ReviewWS" returnType="Struct" output="false" access="remote">
                <cfset response_XML = XmlParse("\\ServerName\XMLDocuments\Review10.xml")>

                <cfset NoOfPeople = ArrayLen(XmlSearch(response_XML,"/p1:ReviewReport/p3:Person"))>

                <cftransaction action="BEGIN">
                <cftry>

                <cfloop from="1" to="#ListLen(NoOfPeople)#" index="i">
                <cfmodule template="#Form.FileLoc#/review_ins.cfm"
                review_no="#Form.review_no#"
                user_add="#Request.user_add#"
                source_add="#Request.source_add#"
                seq_no="#i#">
                <cfset response.count = i>
                </cfloop>
                <cfcatch>
                <cftransaction action="ROLLBACK"/>
                <cfrethrow>
                </cfcatch>
                </cftry>
                </cffunction>
                </cfcomponent>


                Message : Could not perform web service invocation "ReviewWS".

                Detail : Here is the fault returned when invoking the web service operation:

                AxisFault
                faultCode: { http://schemas.xmlsoap.org/soap/envelope/}Server.userException
                faultSubcode:
                faultString: coldfusion.xml.rpc.CFCInvocationException:
                [coldfusion.runtime.UndefinedElementException : Element user_add is undefined in REQUEST.]
                faultActor:
                faultNode:
                faultDetail:
                { http://xml.apache.org/axis/}stackTrace:coldfusion.xml.rpc.CFCInvocationException: [coldfusion.runtime.UndefinedElementException : Element user_add is undefined in REQUEST.]
                at coldfusion.xml.rpc.CFComponentSkeleton.__createCFCInvocationException(CFComponentSkeleton .java:717)
                at coldfusion.xml.rpc.CFComponentSkeleton.__invoke(CFComponentSkeleton.java:663)
                at ReviewWs.ReviewWS(C:\Inetpub\wwwroot\ReviewWs.cfc)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                at java.lang.reflect.Method.invoke(Method....

                • 5. Re: Accesing Form and Request variables in cfc
                  Level 7
                  No, you need to uses arguments and pass in the form values you want to use.

                  Something like this.

                  <cfinvoke webservice="ws_ReviewSheet"
                  method="ReviewWS"
                  argumentCollection="#form#"
                  returnVariable="response">
                  </cfinvoke>

                  <!--- CFC Code --->
                  <cfcomponent>
                  <cffunction name="ReviwWS"...>
                  ...
                  <cfmodule template="#arguments.FileLoc#"/review_ins.cfm"...
                  ...
                  </cfcomponent>

                  cfchick12 wrote:
                  > Hi,
                  > Thank you for the response, I guess I can't use form or request variables. I
                  > think I have to parse and return response back as a return value and do my
                  > inserts. Below is my code, the variables are defined in the page where I am
                  > invoking the webservice.
                  >
                  > <!---Function Invoked--->
                  > <cfinvoke
                  > webservice="ws_ReviewSheet"
                  > method="ReviewWS"
                  > returnvariable="response">
                  > </cfinvoke>
                  >
                  > <!---cfc Code--->
                  > <cfcomponent>
                  > <cffunction name="ReviewWS" returnType="Struct" output="false"
                  > access="remote">
                  > <cfset response_XML = XmlParse("\\ServerName\XMLDocuments\Review10.xml")>
                  >
                  > <cfset NoOfPeople =
                  > ArrayLen(XmlSearch(response_XML,"/p1:ReviewReport/p3:Person"))>
                  >
                  > <cftransaction action="BEGIN">
                  > <cftry>
                  >
                  > <cfloop from="1" to="#ListLen(NoOfPeople)#" index="i">
                  > <cfmodule template="#Form.FileLoc#/review_ins.cfm"
                  > review_no="#Form.review_no#"
                  > user_add="#Request.user_add#"
                  > source_add="#Request.source_add#"
                  > seq_no="#i#">
                  > <cfset response.count = i>
                  > </cfloop>
                  > <cfcatch>
                  > <cftransaction action="ROLLBACK"/>
                  > <cfrethrow>
                  > </cfcatch>
                  > </cftry>
                  > </cffunction>
                  > </cfcomponent>
                  >
                  >
                  > Message : Could not perform web service invocation "ReviewWS".
                  >
                  > Detail : Here is the fault returned when invoking the web service operation:
                  >
                  > AxisFault
                  > faultCode: { http://schemas.xmlsoap.org/soap/envelope/}Server.userException
                  > faultSubcode:
                  > faultString: coldfusion.xml.rpc.CFCInvocationException:
                  > [coldfusion.runtime.UndefinedElementException : Element user_add is undefined
                  > in REQUEST.]
                  > faultActor:
                  > faultNode:
                  > faultDetail:
                  >
                  > { http://xml.apache.org/axis/}stackTrace:coldfusion.xml.rpc.CFCInvocationExcepti
                  > on: [coldfusion.runtime.UndefinedElementException : Element user_add is
                  > undefined in REQUEST.]
                  > at
                  > coldfusion.xml.rpc.CFComponentSkeleton.__createCFCInvocationException(CFComponen
                  > tSkeleton.java:717)
                  > at
                  > coldfusion.xml.rpc.CFComponentSkeleton.__invoke(CFComponentSkeleton.java:663)
                  > at ReviewWs.ReviewWS(C:\Inetpub\wwwroot\ReviewWs.cfc)
                  > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                  > at
                  > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                  > at
                  > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
                  > a:25)
                  > at java.lang.reflect.Method.invoke(Method....
                  >
                  >
                  >
                  • 6. Re: Accesing Form and Request variables in cfc
                    cfchick12 Level 1
                    I think, I need Form, Request and Session variables. The tags which I am using are all common tags, which are used through out the application. So changing it to "Arguments." just for this scenario is a pain. I have pasted only a tiny bit of the code. I have lots of cfmodules and cfincludes which again uses the form and request variables. Thanks for your valuable suggestions/comments.