4 Replies Latest reply on Sep 20, 2006 8:05 PM by nyfeman

    Remoting Help

    jfillman Level 1
      I'm brand new to Flex. Have worked with ColdFusion for a while, but just started using CFC's. I really need some help with something that seems basic enough, but I can't find any examples that are simple enough that I can get this to work.

      I have an application with username and password textinput boxes. I want to pass the text from those two fields to the cfc and return "true" if there was a match and false if there was no match.

      From there I have two questions. First, how do I return the literal "true" or "false" to a label so that I know it is returning the right thing. Second, how do I change the state based on a "true" result?

      I imaging this is not the best way to create a login page, but this is more for me to see how Flex and ColdFusion work together. I'm not clearly understanding how the data is being passed on processed between them.

      cfc code:

      <cfcomponent name="userList" access="public">

      <cffunction name="getUser" access="remote" returntype="query" description="Returns patient's forms">
      <cfargument name="id" type="string" required="yes">
      <cfargument name="password" type="string" required="yes">

      <CFQUERY NAME="formSearch" DATASOURCE="testdb" MAXROWS=1>
      SELECT *
      FROM appusers
      WHERE User_Id="#arguments.id#" and Password="#arguments.password#"
      <cfif formSearch.RecordCount LT 1>
      <CFRETURN "false">
      <CFRETURN "true">
        • 1. Re: Remoting Help
          peterent Level 2
          Your CFC looks fine - returning "true" and "false", but I would change the returntype to string because that's what you want to return. However, you could change the returntype to any and I believe you will get actual Boolean values back in Flex.

          In your RemoteObject tag, add a result handler for the cffunction:

          <mx:method name="getUser" result="handleGetUserResult(event)" />

          private function handleGetUserResult( event:ResultEvent ) : void
          if( event.result == "true" ) { // or if( Boolean(event.result) ) {
          do something like currentState='loginOKState';
          } else {
          do something else like currentState='loginFailState';

          This assumes you have 2 states: <mx:state name="loginOKState" > and <mx:state name="loginFailState" >
          • 2. Re: Remoting Help
            nyfeman Level 1
            Just to introduce some variety to the discussion, I have a login sequence similar to the one above (one small difference, I do a SELECT statement based on username and then compare the provided password with the password from the database and set a variable to the result of that comparison and return the variable as a boolean).

            On the user side, the initial state is my login screen. If the login passes, it goes to the "application" state and if it fails, it stays in the login state but puts up an Alert notifying the user of their bad username/password.
            • 3. Re: Remoting Help
              jfillman Level 1
              First of all, thank you for the replies. Would you be willing to post some sample Flex code that changes the state based on the result from the CFC. I'd also like to know how to bind the returned result to a label.
              • 4. Remoting Help
                nyfeman Level 1
                This is the RemoteObject
                <mx:RemoteObject id="svcLogin" destination="ColdFusion" source="SPTRoster"
                result="openDoor(event)" fault="Alert.show(event.fault.message)" showBusyCursor="true">
                <mx:method name="setData">

                This is from the CFC:
                <cffunction name="setData" access="remote" returntype="boolean">
                <cfargument name="userName" required="yes" type="string"/>
                <cfargument name="pWord" required="yes" type="string"/>
                <cfparam name="userName" type="string"/>
                <cfparam name="pWord" type="string"/>
                <cfquery datasource="Roster" name="frontDoor" debug="yes">
                SELECT username, password
                FROM tblRoster
                WHERE username = '#userName#'
                <cfset password = '#frontDoor.password#'>
                <cfif #password# IS #pWord#>
                <cfset opened = true>
                <cfset opened = false>
                <cfreturn opened>

                This is the ActionScript that opens the door:

                private var logger:String;
                private function openDoor(event:ResultEvent):void
                logger = event.result as String;
                if(logger == "true")
                //the state default is "login", it's changed to the base state below.
                Alert.show("You have entered an incorrect UserName/Password Combination");