11 Replies Latest reply on May 11, 2009 8:25 AM by Michael Borbor

    ColdFusion CFC and Flex faults

    tietack

      Good Afternoon:

       

      I am attempting to trigger the fault event of a RemoteObject call to a method in a CFC.

       

      I am calling a CFC function through a Flex front end. I am using an example I found on the web doing just what I am looking to do. However, it is not performing the same as the example. This is the link for the example.

       

      http://www.brucephillips.name/flex/HandleCFCException/HandleCFCException.html

       

      I am attempting to use cfthrow to trigger the fault event. However, whenever I run the above example code on my server, it always triggers the result event. Are there any specific settings within the CF administrator that would need to be setup to ensure these fault events are registered?

       

      Thank you,

      Jamee Tadej

        • 1. Re: ColdFusion CFC and Flex faults
          Michael Borbor Level 4

          James alter your CFC and add a cftrow tag so whenever you call your 

          method it'll return an error, I'm assuming you want to play a little 

          bit with errors and error handling in Flex

           

          Sincerely,

           

          Michael

           

          El 08/05/2009, a las 15:55, tietack <forums@adobe.com> escribió:

           

          >

          Good Afternoon:

          >

          I am attempting to trigger the fault event of a RemoteObject call to 

          a method in a CFC.

          >

          I am calling a CFC function through a Flex front end. I am using an 

          example I found on the web doing just what I am looking to do. 

          However, it is not performing the same as the example. This is the 

          link for the example.

          >

          http://www.brucephillips.name/flex/HandleCFCException/HandleCFCException.html

          >

          I am attempting to use cfthrow to trigger the fault event. However, 

          whenever I run the above example code on my server, it always 

          triggers the result event. Are there any specific settings within 

          the CF administrator that would need to be setup to ensure these 

          fault events are registered?

          >

          Thank you,

          Jamee Tadej

          >

          • 2. Re: ColdFusion CFC and Flex faults
            tietack Level 1

            Thank you for the quick response. I currently have a cfthrow in the CFC; however, when the cfc function is called, it always triggers the result function.

             

            My remote object method looks like

             

                  <mx:method name="throwAnError" result="Alert.show('This is the result!)" fault="Alert.show('This is the fault!)" />

             

            My CFC function looks like

             

                 <cffunction name="throwAnError" returntype="void" access="remote" output="false">
                      <cfthrow message="This is an error message." />

                 </cffunction>

            Everytime I call the throwAnError function, I get an alert popup with 'This is the result!'

             

            It seems to be I should be receiving the 'This is the fault!' message. In the link I provded above, there is an example of exactly what I am trying to do. When I changed my code to use the code from the sample, I get same result as I did above. The result function is called everytime. It is like it is ignoring the cfthrow tag.

             

            Any thoughts?

            • 3. Re: ColdFusion CFC and Flex faults
              Michael Borbor Level 4

              Interesting in a few minutes I'll get home and I'll try to reproduce 

              your flex/gf app to see what comes up.

               

              Sincerely,

               

              Michael

               

              El 08/05/2009, a las 16:10, tietack <forums@adobe.com> escribió:

               

              >

              Thank you for the quick response. I currently have a cfthrow in the 

              CFC; however, when the cfc function is called, it always triggers 

              the result function.

              >

              My remote object method looks like

              >

                    <mx:method name="throwAnError" result="Alert.show('This is the 

              result!)" fault="Alert.show('This is the fault!)" />

              >

              My CFC function looks like

              >

                   <cffunction name="throwAnError" returntype="void" 

              access="remote" output="false">

                        <cfthrow message="This is an error message." />

                   </cffunction>

              Everytime I call the throwAnError function, I get an alert popup 

              with 'This is the result!'

              >

              It seems to be I should be receiving the 'This is the fault!' 

              message. In the link I provded above, there is an example of exactly 

              what I am trying to do. When I changed my code to use the code from 

              the sample, I get same result as I did above. The result function is 

              called everytime. It is like it is ignoring the cfthrow tag.

              >

              Any thoughts?

              >

              • 4. Re: ColdFusion CFC and Flex faults
                tietack Level 1

                Thank you. I am using the Developer Edition running a local server, just FYI.

                • 5. Re: ColdFusion CFC and Flex faults
                  Michael Borbor Level 4

                  Hi there, I just created a Flex/CF project and it threw an error. This is my code

                   

                  Flex App

                   

                   

                  ?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="myError.throwAnError()">
                  <mx:Script>
                       <![CDATA[
                            import mx.rpc.events.ResultEvent;
                            import mx.rpc.events.FaultEvent;
                            import mx.controls.Alert;
                            
                            private function myFaultHandler(e:FaultEvent):void{
                                 Alert.show(e.fault.toString())     
                            }
                            
                            private function myResultHandler(e:ResultEvent):void{
                                 Alert.show(e.result.toString())     
                            }
                            
                       ]]>
                  </mx:Script>
                       <mx:RemoteObject id="myError"  destination="ColdFusion" source="Errors">
                            <mx:method name="throwAnError" result="myResultHandler(event)" fault="myFaultHandler(event)"/>
                       </mx:RemoteObject>
                       <mx:Button label="Click me" click="myError.throwAnError()" />
                  </mx:Application>
                  

                   

                   

                  I use the same CF code as you did

                   

                  <cfcomponent>
                  <cffunction name="throwAnError" returntype="void" access="remote" output="false">
                            <!--- <cfreturn 2 /> --->
                         <cfthrow message="This is an error message." />
                  
                       </cffunction>
                  </cfcomponent>
                  

                  And it work, you could post your whole Flex/CF code to see if there's something missing.

                  1 person found this helpful
                  • 6. Re: ColdFusion CFC and Flex faults
                    tietack Level 1

                    Thank you for taking the time. I had written anohter entry on Friday, but it does not seem to have posted. I do not know why.

                     

                    I figured out the culprit to my problem. I was also using an Application.cfc file. I had noticed when I first added the file, that I was unable to see any results when I ran the method directly through the URL, even when sending in appropriate values. When I removed the Application.cfc file from my root folder, the results would display. Also, I did not include the onRequest function in my cfc because I had read that would break the flash remoting calls.

                     

                    So I began commenting out the other functions in the component one by one until I found the culprit. I also had a generic onError function within my Application.cfc. It seems that this function was catching the errors in the cfc instead of passing it through to the Flex application to handle.

                     

                    Thanks for your help. Hopefully anyone else who encounters this may find this information useful.

                    • 7. Re: ColdFusion CFC and Flex faults
                      tietack Level 1

                      I do have one other quick question, though.

                       

                      I am now catching the error message in my fault handler. In my cfc i am creating an error message with line breaks (\n). However, when the fault handler displays this in an Alert, the line breaks are text, and no longer read as line breaks. Any idea how to ensure they are translated properly rather than just text?

                      • 8. Re: ColdFusion CFC and Flex faults
                        Michael Borbor Level 4

                        Hi, I'm glad you solve your problem, the Application.cfc must've been 

                        catching the errors. Please don't forget to mark your own post as 

                        answer so it'll be helpful for others.

                         

                        Sincerely,

                         

                        Michael

                        • 9. Re: ColdFusion CFC and Flex faults
                          Michael Borbor Level 4

                          Try escaping the \ use
                          n

                           

                          Sincerely,

                           

                          Michael

                           

                          El 11/05/2009, a las 10:15, tietack <forums@adobe.com> escribió:

                           

                          >

                          I do have one other quick question, though.

                          >

                          I am now catching the error message in my fault handler. In my cfc i 

                          am creating an error message with line breaks (\n). However, when 

                          the fault handler displays this in an Alert, the line breaks are 

                          text, and no longer read as line breaks. Any idea how to ensure they 

                          are translated properly rather than just text?

                          >

                          • 10. Re: ColdFusion CFC and Flex faults
                            tietack Level 1

                            Thank you again for the quick response.

                             

                            Good idea. I did try escaping the '/'. I used '//n', however it was still just interpretted as text.

                             

                            Since the cfc is being processed by the ColdFusion server, I decided to try including CF characters for line breaks [ chr(13)chr(10) ].

                             

                            It worked. If I used both chr(13)chr(10) it was equivalent to using /n/n. If I used chr(10), it would acheive the same effect as /n.

                             

                            Thanks again for the assistance!

                            • 11. Re: ColdFusion CFC and Flex faults
                              tietack Level 1

                              CORRECTION

                               

                              in my previous post I stated I was using the '/' slash, but I mistyped. I was using the '\' slash.