2 Replies Latest reply on Jun 27, 2007 6:22 PM by jasonpresley

    Query not being returned to Flex

    jasonpresley
      I am trying to pass a username and password to a CFC. If I hard code the values in the CFC it works like I expect but when I try to pass them I get a blank datagrid.

      memberDAOMod.cfc
      <cfcomponent output="true">
      <cffunction name="readLogin" access="remote" returntype="query">
      <cfargument name="username" required="true">
      <cfargument name="password" required="true">
      <cfset var qRead="">
      <cfquery name="qRead" datasource="muller_central">
      select *
      from member
      where memUsername = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.username#" />
      and memPassword = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.password#" />
      </cfquery>
      <cfreturn qRead/>
      </cffunction>
      </cfcomponent>

      memberLogin.mxml
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="initApp()">

      <mx:Script>
      <![CDATA[
      import mx.rpc.events.ResultEvent;
      import mx.collections.ArrayCollection;

      [Bindable]
      private var acMember:ArrayCollection;

      private function initApp():void {
      checkLogin.readLogin('jpresley','n7140067');
      }

      public function resultMemberLogin(event:ResultEvent):void {
      acMember = ArrayCollection(event.result);
      }

      ]]>
      </mx:Script>

      <mx:RemoteObject id="checkLogin" destination="ColdFusion" source="MullerIntranet.memberDAOMod" showBusyCursor="true">
      <mx:method name="readLogin" result="resultMemberLogin(event)"/>
      </mx:RemoteObject>

      <mx:DataGrid dataProvider="{acMember}">
      </mx:DataGrid>
      </mx:Application>

      If I change the initApp function to this:
      private function initApp():void {
      checkLogin.readLogin();
      }
      it fails because the CFC arguments username and password are set as required. However, when I pass them through the initApp function (and hard code the values into to the where statement) it works.

      Can anyone help? I am totally confused as to why I am getting a blank datagrid.

      Thanks
        • 1. Re: Query not being returned to Flex
          YossarianXOS
          For some reason (and it is probably ignorance on my part), I can never get RemoteObject methods to work unless I declare all of the required parameters in an <mx:arguments> tag inside the method. What I put in can be blank, though! Really kind of wierd, but we've taken to just explicitly spelling out the parameters the method takes in (which probably isn't a bad thing for maintenence anyway).

          Anyhow, try changing your method to look like this:

          <mx:method name="readLogin" result="resultMemberLogin(event)">
          <mx:arguments>
          <username/>
          <password/>
          </mx:arguments>
          </mx:method>
          • 2. Re: Query not being returned to Flex
            jasonpresley Level 1
            <cfqueryparam cfsqltype="CF_SQL_ INTEGER" value="#arguments.username#" />

            Should have been...

            <cfqueryparam cfsqltype="CF_SQL_ VARCHAR" value="#arguments.username#" />