Skip to main content
Known Participant
August 13, 2009
Question

Return custom Component from CF to flex?

  • August 13, 2009
  • 2 replies
  • 2795 views

Hi,

i am in huge a desperate state...

My Idea:

I have an Air-App wich read out the Database with Coldfusion remoting - So far no Problem. Now i create a Component inside Coldfusion, wich represents a User from the Database.

<cfcomponent displayname="CurrentUserVO" hint="Represents the logged in User" output="false">
    <cfset this.username = "" />
    <cfset this.password = "" />
   
    <cfset this.firstname = "" />
    <cfset this.lastname = "" />
</cfcomponent>

I create a Query, read out the Database and "parse" the DatabaseContent to this component. Now... I want to return this "Custom Component" to Flex, but that doesn't work

I can return the whole querry or a property of the Component (such as lastname or firstname) but not the complete Componente. (Flex Result == null)

It would be awesome if someone can help me, i think for a Colfusion-Expert this isn't a big thing?

Greets from Germany,

Nico

Ps: @ Adobe: The Coldfusion-"Community" in Germany i on a very very low level ! (There are just a few people)

This topic has been closed for replies.

2 replies

Inspiring
August 13, 2009

i would probably create my VO like:

<cfcomponent displayname="CurrentUserVO" hint="Represents the logged in User" output="false">

     <cfproperty name="username" type="string" />
     <cfproperty name="password" type="string" />   
     <cfproperty name="firstname" type="string" />
     <cfproperty name="lastname" type="string" />

     <cfparam name="username" type="string" default="" />
     <cfparam name="password" type="string" default="" />  
     <cfparam name="firstname" type="string" default="" />
      <cfparam name="lastname" type="string" default="" />

<cffunction name="init" access="public" returntype="CurrentUserVO">
        <cfscript>
            var key="";
            for (key in arguments) {
                this[key] = arguments[key];
            }
            return this;
        </cfscript>
    </cffunction>


</cfcomponent>

maeldanusAuthor
Known Participant
August 13, 2009

Oh...forget to post the "call"

<cfcomponent hint="Exchange" output="false">

<cfobject name="currentuserVO" component="CurrentUserVO">

<!-- cfc property names -->


    <cffunction name="login" displayname="login" access="remote" output="false" >
            <cfargument name="username"  required="true"  type="String">
            <cfargument name="password"  required="true"  type="String">
               
               
                <cfquery name="Meinquery" datasource="cfagency" username="root" password="">
                    SELECT * FROM user WHERE username= '#username#' AND password = '#password#'
                </cfquery>
                           
               
                <cfif isDefined("Meinquery")>
                    <cfscript>
                        currentuserVO.username  = Meinquery.username;
                        currentuserVO.password  = Meinquery.password;
                        currentuserVO.firstname = Meinquery.firstname;
                        currentuserVO.lastname  = Meinquery.lastname;   
                    </cfscript>
                   
                    <cfreturn #currentuserVO# >
               
                <cfelse>
                    <cfreturn "false" >
                </cfif>   
               
    </cffunction>

Greets, nico

Inspiring
August 13, 2009

...and maybe make a few changes

<cffunction name="login" displayname="login" access="remote" output="false" >
<cfargument name="username"  required="true"  type="String">
<cfargument name="password"  required="true"  type="String">
             <cfset var Meinquery="">

             <cfset var thisUserVO=createObject("component","CurrentUserVO")>
               
                <cfquery name="Meinquery" datasource="cfagency" username="root" password="">
                    SELECT *

                    FROM user

                    WHERE username= '#arguments.username#' AND password = '#arguments.password#'
                </cfquery>

                <cfset thisUserVO.init(username = Meinquery.username,password=Meinquery.password,

                firstname=Meinquery.firstname,lastname=Meinquery.lastname)> 
              <cfreturn #thisUserVO# >
    </cffunction>

how are you calling that function on the flex end? you seem to be returning two different kinds of datatypes, a boolean and the CurrentUserVO.

maeldanusAuthor
Known Participant
August 13, 2009

Hi,

thanks for your Answer (i will try it in a few minutes)

I user a remote Object and that's it. (in Flex) For each function i hve different Result/fault Handlers...

greets, nico

Edit: It totally make sense, what u wrote... but isn't it a bit "too" much in one Component if i write there all my "custom Compos" ?