Skip to main content
Inspiring
February 18, 2011
Question

getHumansThisPlanet.cfc error

  • February 18, 2011
  • 3 replies
  • 3212 views

I don't know if this is a bind problem or not - I'm not getting an error, I'm getting empty dropdowns on the form page. (The

cfc and cfm both reside in the same folder.) I've googled this planet and just can't find why the form selects aren't

dynamically loading from the cfc - What am I missing here? (This is based on Forte's cfc dynamic selects.)

Thanks for anyone's advice...

- e


********************* getHumansThisPlanet.cfc

<cfcomponent output="false">

    <cfset THIS.dsn="#application.dsn#">

    <!--- Get array of Places --->
<cffunction name="getPlanets" access="remote" returnType="array">
        <!--- Define variables --->
        <cfset var data="">
        <cfset var result=ArrayNew(2)>
        <cfset var i=0>

    <!--- Get Places --->       
<CFQUERY NAME="PlanetData" DATASOURCE="#THIS.dsn#">
SELECT DISTINCT PlanetNumber, PlanetName
FROM PlanetTable
     WHERE AdminLevel = 'three' AND PlanetYear = '2010-2011' AND ParticipationLevel = 'jumpingUpandDown'
     ORDER BY PlanetName ASC;
</cfquery>

    <!--- Convert results to array --->
        <cfloop index="i" from="1" to="#PlanetData.RecordCount#">
            <cfset result[1]=PlanetData.PlanetNumber>
            <cfset result[2]=PlanetData.PlanetName>
        </cfloop>

    <!--- And return it --->
        <cfreturn result>
    </cffunction>

    <!--- Get Humans by Planet --->
    <cffunction name="getHumans" access="remote" returnType="array">
        <cfargument name="PlanetNumber" type="numeric" required="true">

    <!--- Define variables --->
        <cfset var data="">
        <cfset var result=ArrayNew(2)>
        <cfset var i=0>
       
    <!--- Get data --->
        <cfquery name="HumanData" datasource="#THIS.dsn#">
        SELECT HumanID, PlanetNumber, Lname + ', ' + Fname AS FullName
        FROM HumanTable
        WHERE PlanetNumber = #ARGUMENTS.PlanetNumber#
        ORDER BY Lname ASC;
        </cfquery>

    <!--- Convert results to array --->
        <cfloop index="i" from="1" to="#HumanData.RecordCount#">
            <cfset result[1]=HumanData.HumanID>
            <cfset result[2]=HumanData.Fullname>
        </cfloop>

    <!--- And return it --->
        <cfreturn result>
</cffunction>

</cfcomponent>

********************* CFM page

<cfform action="EmailThisHuman.cfm" method="POST">
    <input type="hidden" name="SendTo" value="THIS Human THIS Planet">

  <tr>
    <td height="40" align="left" valign="middle" bgcolor="#FFFFFF"> </td>

    <td height="40" align="left" valign="middle" bgcolor="#FFFFFF">

    <span class="eleven_pt_bold_blue_ariel">Email THIS Human THIS Planet</span>

    <img src="transparent.gif" width="15" height="1" alt="spacer" />
   
                 <cfselect name="getPlanets"
                 message="------ Select Planet ------"
                 bind="cfc:getHumansThisPlanet.getPlanets()"
                 size="1"
                 onChange="document.getElementById('getHumans').style.visibility='visible'"
  bindonload="true" />
               
    <img src="transparent.gif" width="15" height="1" alt="spacer" />
               
                <cfselect name="getHumans"
                bind="cfc:getHumansThisPlanet.getHumans({FullName})"
                message="----- Select Human -----"
                style="visibility:hidden"
                id="getHumans"
                onChange="document.getElementById('HumanSubmitButton').style.visibility='visible'" />
               
    <img src="transparent.gif" width="15" height="1" alt="spacer" />
    
    <input type="submit" name="HumanSubmitButton" id="HumanSubmitButton" value="Submit" style="visibility:hidden" />

    </td>
    <td height="40" align="left" valign="middle" bgcolor="#FFFFFF"> </td>
  </tr>

</cfform>

    This topic has been closed for replies.

    3 replies

    BKBK
    Community Expert
    Community Expert
    February 20, 2011

    Is there a mapping to C:\ColdFusion9\wwwroot\CFIDE in the ColdFusion Administrator? Does this directory exist: C:\ColdFusion9\wwwroot\CFIDE\scripts\?

    NessmukAuthor
    Inspiring
    February 20, 2011

    Thanks, BKBK...

    Maybe that's the problem.

    It does seem that everything is set up fine and the queries are actually pulling data when a test is run.

    This is on a website hosted on a shared server. I understood that there was no special mapping if the cfm and cfc was in the same folder.

    Do I need to set up a CFIDE/script folder in the root with mapping pointing to it to run a cfc? (This is a CF website at Intermedia dotnet)

    - e

    NessmukAuthor
    Inspiring
    February 21, 2011

    Thanks again to everyone responding here... especially BKBK who's gone to great lengths in helping me...

    This is got to be some kind of bind issue. The test cfm is working just fine, so the queries do run. The selects just do not fill when the cfm calls to the cfc page.

    I didn't think mapping would be an issue here since I've read that a cfm and cfc doesn't have to have any special mapping if they are both in the same folder. Is this correct?

    But this does seem to be some kind of bind issue since the test cfm runs just fine...

    - e

    BKBK
    Community Expert
    Community Expert
    February 19, 2011

    More suggestions

    1) You should already have spotted that the following tag needs closing

    <cfset random_row_number = randRange(1, planetData.recordcount)>

    2) Use
    <cfset result[1][1]="">
    <cfset result[1][2]="------ Select Planet ------">
    <cfloop query="PlanetData">
        <cfset result[currentrow+1][1]=planetNumber>
        <cfset result[currentrow+1][2]=planetName>
    </cfloop>

    instead of

    <cfloop index="i" from="1" to="#PlanetData.RecordCount#">
        <cfset result[1]=PlanetData.PlanetNumber>
        <cfset result[2]=PlanetData.PlanetName>
    </cfloop

    3) Use
    <cfset result[1][1]="">
    <cfset result[1][2]="------ Select Human ------">
    <cfloop query="HumanData">
        <cfset result[currentrow+1][1]=humanID>
        <cfset result[currentrow+1][2]=fullname>
    </cfloop>

    instead of

    <cfloop index="i" from="1" to="#HumanData.RecordCount#">
        <cfset result[1]=HumanData.HumanID>
        <cfset result[2]=HumanData.Fullname>
    </cfloop>

    4) Use as the first select:
    <cfselect name="planet"
                    bind="cfc:getHumansThisPlanet.getPlanets()"
                    size="1"
                    onChange="document.getElementById('human').style.visibility='visible'"
              bindonload="true" />

    5) Use as the second select:
      <cfselect name="human"
                    bind="cfc:getHumansThisPlanet.getHumans({planet})"
                    style="visibility:hidden"
                    id="human"
                    onChange="document.getElementById('HumanSubmitButton').style.visibility='visible'" />
                   



    NessmukAuthor
    Inspiring
    February 20, 2011

    Thanks to all of you looking at this...

    The queries do run. When I did the "test" from BKBK (see above - planetTest.cfm) this test page does pull the fields from the database.

    I just tried BKBK's new code and I'm still getting the same result - a blank dropdown.

    I do have de-bugging on and it's not throwing an error. The cfm page displays correctly - but the first dropdown is still empty.

    For a fresh outlook... The following is the current code as per BKBK's latest suggestions... which is still not populating the select.

    (The following is the original code -- "teacher" replaces "human" and "school" replaces "planet". I changed the field names in the original post in just trying to gain an understanding on how all this works instead of someone 'fixing my code' - I want to understand the whole process since this is my first try at building a cfc page. It was starting to get confusing to me to reword everything to run on the server.)

    Thanks again, y'all...

    - e


    **************cfc

    <cfcomponent output="false">

        <cfset THIS.dsn="#application.dsn#">

        <!--- Get array of Schools --->
        <cffunction name="getSchools" access="remote" returnType="array">
            <!--- Define variables --->
            <cfset var data="">
            <cfset var result=ArrayNew(2)>
            <cfset var i=0>

            <!--- Get Schools --->       
            <CFQUERY NAME="SchoolData" DATASOURCE="#THIS.dsn#">
    SELECT DISTINCT
         schoolNumber, SchoolName
    FROM
      teacher_logon
        WHERE AdmnLevel = 'tchr' AND SchoolYear = '2010-2011' AND ParticipationLevel = 'active'
        ORDER BY SchoolName ASC;
      </cfquery>

            <!--- Convert results to array --->
           
        <cfset result[1][1]="">
    <cfset result[1][2]="------ Select School ------">
    <cfloop query="SchoolData">
        <cfset result[currentrow+1][1]=schoolNumber>
        <cfset result[currentrow+1][2]=SchoolName>
    </cfloop>

            <!--- And return it --->
            <cfreturn result>
        </cffunction>

        <!--- Get Teachers by School --->
        <cffunction name="getTeachers" access="remote" returnType="array">
            <cfargument name="schoolNumber" type="numeric" required="true">

            <!--- Define variables --->
            <cfset var data="">
            <cfset var result=ArrayNew(2)>
            <cfset var i=0>
           
            <!--- Get data --->
            <cfquery name="TeacherData" datasource="#THIS.dsn#">
            SELECT adminID, schoolNumber, Lname + ', ' + Fname AS FullName
            FROM teacher_logon
            WHERE schoolNumber = #ARGUMENTS.schoolNumber#
            ORDER BY Lname ASC;
            </cfquery>

            <!--- Convert results to array --->
           
        <cfset result[1][1]="">
    <cfset result[1][2]="------ Select Teacher ------">
    <cfloop query="TeacherData">
        <cfset result[currentrow][1]=adminID>
        <cfset result[currentrow][2]=Fullname>
    </cfloop>

            <!--- And return it --->
            <cfreturn result>
        </cffunction>

    </cfcomponent>

    *****************cfm

    <cfform action="EmailTeacherThisSchool.cfm" method="POST">
        <input type="hidden" name="SendTo" value="THIS Teacher THIS School">
      <tr>
        <td height="40" align="left" valign="middle" bgcolor="#FFFFFF"> </td>
        <td height="40" align="left" valign="middle" bgcolor="#FFFFFF">
        <span class="eleven_pt_bold_blue_ariel">Email THIS  Teacher THIS School</span>
        <img src="transparent.gif" width="15" height="1" alt="spacer" />
       
        <cfselect name="School"
                    bind="cfc:getTeachersThisSchool.getSchools()"
                    size="1"
                    onChange="document.getElementById('Teacher').style.visibility='visible'"               
                    bindonload="true" />
                   
        <img src="transparent.gif" width="15" height="1" alt="spacer" />
                   
                    <cfselect name="Teacher"
                    bind="cfc:getTeachersThisSchool({School})"
                    style="visibility:hidden"
                    id="Teacher"
                    onChange="document.getElementById('TeacherSubmitButton').style.visibility='visible'" />
                   
        <img src="transparent.gif" width="15" height="1" alt="spacer" />
        
        <input type="submit" name="TeacherSubmitButton" id="TeacherSubmitButton" value="Submit" style="visibility:hidden" />
        </td>
        <td height="40" align="left" valign="middle" bgcolor="#FFFFFF"> </td>
      </tr>
      </cfform>

    BKBK
    Community Expert
    Community Expert
    February 20, 2011

    I finally decided to run your code. When I put the following 2 files in a test directory, the test CFM file ran as expected.

    My database server is MySQL 5. Also, note the use of   <cfset result[1][1]="0"> in place of  <cfset result[1][1]="">. That is because this value is the default option which the bind sends as an argument to the getHumans() function.  The function requires a numeric argument.

    getHumansThisPlanet.cfc

    <cfcomponent output="false">

        <cfset THIS.dsn="cfmx_db">

        <!--- Get array of Places --->

    <cffunction name="getPlanets" access="remote" returnType="array">
            <!--- Define variables --->
            <cfset var data="">
            <cfset var result=ArrayNew(2)>
            <cfset var i=0>

        <!--- Get Places --->      
        <CFQUERY NAME="PlanetData" DATASOURCE="#THIS.dsn#">
        SELECT DISTINCT PlanetNumber, PlanetName
        FROM PlanetTable
        ORDER BY PlanetName ASC;
        </cfquery>
       
            <!--- Convert results to array --->
        <cfset result[1][1]="0">
        <cfset result[1][2]="------ Select Planet ------">
         <cfloop query="PlanetData">
            <cfset result[currentrow+1][1]=planetNumber>
            <cfset result[currentrow+1][2]=planetName>
        </cfloop>
          <!--- And return it --->
            <cfreturn result>
        </cffunction>

    <!--- Get Humans by Planet --->
    <cffunction name="getHumans" access="remote" returnType="array">
        <cfargument name="PlanetNumber" type="numeric" required="true">

        <!--- Define variables --->
            <cfset var data="">
            <cfset var result=ArrayNew(2)>
            <cfset var i=0>
          
        <!--- Get data --->
            <cfquery name="HumanData" datasource="#THIS.dsn#">
            SELECT HumanID, PlanetNumber, concat(Lname , ', ' , Fname) AS FullName
            FROM HumanTable
            WHERE PlanetNumber = #ARGUMENTS.PlanetNumber#
            ORDER BY Lname ASC;
            </cfquery>

        <!--- Convert results to array --->
        <cfset result[1][1]="0">
        <cfset result[1][2]="------ Select Human ------">
        <cfloop query="HumanData">
            <cfset result[currentrow+1][1]=humanID>
            <cfset result[currentrow+1][2]=fullname>
        </cfloop>
       
        <!--- And return it --->
        <cfreturn result>
    </cffunction>

    </cfcomponent>

    test.cfm

    <cfform action="EmailThisHuman.cfm" method="POST">
        <input type="hidden" name="SendTo" value="THIS Human THIS Planet">
      <tr>
        <td height="40" align="left" valign="middle" bgcolor="#FFFFFF"> </td>
        <td height="40" align="left" valign="middle" bgcolor="#FFFFFF">
        <span class="eleven_pt_bold_blue_ariel">Email THIS Human THIS Planet</span>
    <br>
                     <cfselect name="planet"            
                     bind="cfc:getHumansThisPlanet.getPlanets()"
                     size="1"
                     onChange="document.getElementById('human').style.visibility='visible'"
      bindonload="true" />            
       <br>             
                    <cfselect name="human"
                    bind="cfc:getHumansThisPlanet.getHumans({planet})"
                    style="visibility:hidden"
                    id="human"
                    onChange="document.getElementById('HumanSubmitButton').style.visibility='visible'" />
                  
    <br>
       
        <input type="submit" name="HumanSubmitButton" id="HumanSubmitButton" value="Submit" style="visibility:hidden" />

        </td>
        <td height="40" align="left" valign="middle" bgcolor="#FFFFFF"> </td>
      </tr>
    </cfform>

    BKBK
    Community Expert
    Community Expert
    February 19, 2011

    I can see only one error: you use 'Fullname' in

    bind="cfc:getHumansThisPlanet.getHumans({FullName})"

    whereas the first select field is named 'getPlanets'. In fact, to avoid confusion with the function name (which ColdFusion might also store in memory as a variable!), I would change the name of the first select field from 'getPlanets' to 'planet', and then use

    bind="cfc:getHumansThisPlanet.getHumans({planet})"

    If you still get no data, then test whether the queries are returning data as expected. To do so, create the page planetTest.cfm, containing the following code. Run it several times, for example, by simply refreshing the page. Do you continue to get data?


    <!--- Get Places --->      
    <cfquery name="planetData" datasource="#application.dsn#">
    SELECT DISTINCT PlanetNumber, PlanetName
    FROM PlanetTable
    WHERE AdminLevel = 'three' AND PlanetYear = '2010-2011' AND ParticipationLevel = 'jumpingUpandDown'
    ORDER BY PlanetName ASC;
    </cfquery>

    <cfif planetData.recordcount GT 0>
        <!--- pick the planet from a random row --->
        <cfset random_row_number = randRange(1, planetData.recordcount)
        <cfset random_planetNumber = planetData.planetNumber[random_row_number]>
        Random planet number: <cfoutput>#random_planetNumber#</cfoutput><br>

        <!--- Get data --->
        <cfquery name="HumanData" datasource="#application.dsn#">
        SELECT HumanID, PlanetNumber, Lname + ', ' + Fname AS FullName
        FROM HumanTable
        WHERE PlanetNumber = #random_planetNumber#
        ORDER BY Lname ASC;
        </cfquery>
        Random human data: <cfoutput>id=#HumanData.HumanID#; planetnumber=#HumanData.PlanetNumber#; fullname=#HumanData.FullName#</cfoutput>
    <cfelse>
        The result set planetData contains no data!
    </cfif>

    NessmukAuthor
    Inspiring
    February 19, 2011

    Thanks BKBK!

    The "test" you posted worked just fine -- the queries do run. (Great test code - thanks - I'll use again for other things).

    When I change the {Fullname} to {planet} (after renaming the first select to "planet") on my original form page code... I get a (narrow) blank dropdown... It's not binding to the cfc.

    Thanks so much for looking into this. This is the first cfc I've tried to code... Want to get a handle on how the CF/Ajax works together and understand what's going on.

    - e

    BKBK
    Community Expert
    Community Expert
    February 19, 2011

    Does the 'planet' select list get filled?