Skip to main content
Known Participant
May 15, 2009
Answered

cfcomponent cffunction

  • May 15, 2009
  • 2 replies
  • 1295 views

Hi to all,

i have a cfform input in which i use bind.

in bind there is a function which is written in a cfcomponent.

if i use a variable in that cfcomponent will it re-initialiaze itself in every bind?

ex: <cfcomponent >
<cfset variables.tk='00000'>

<cffunction>
<cfset variables.tk='00012'>
</cffunction>
<cfcomponent >

every time it will bind, the value of the tk variable will be initialized?

if i want to keep that value..is there a way?

    This topic has been closed for replies.
    Correct answer Bert_Dilliën

    Without seeing the code or anything :

    - each new browser request will initialize the component

    - each <cfinvoke> tag will also initialize the component

    If you want to keep the modified value(component ?) over the entire session, you could cach the component in the SESSION scope by using the CreateObject function and using it from there on.

    Cheers,

    Bert.

    2 replies

    Inspiring
    May 15, 2009

    You set a global variable and then changed it inside a function.  If you want to preserve the value, don't change it.

    Known Participant
    May 15, 2009

    Edit

    <cffunction name="gettk" access="remote" returntype="any" output="no">

             <cfargument name="filternomos" type="numeric" required="true">
            <cfargument name="filterarea" type="numeric" required="true">
            <cfargument name="filterodos" type="string" required="true">       
           
            <cfquery name="gettk" datasource="pasent_db" username="root" password="test">
                SELECT tk FROM streets
                WHERE nomos=#ARGUMENTS.filternomos# and muni=#ARGUMENTS.filterarea# and
                str='#ARGUMENTS.filterodos#'
            </cfquery>
           
           
            <Cfif #gettk.recordcount# gt 0>
                <cfset  remembertk(gettk.tk)>
                <cfreturn variables.prevtk>
            <cfelse>
                <cfreturn variables.prevtk>
            </Cfif>

        </cffunction>

    Yes thats what i want to happen. to change if it found a record or leave it as it is...

    But when the bind happens and no records are returned i still get the initialized value of the variables.tk which is 00000 and not the the value of the result of the previous query

    Bert_DilliënCorrect answer
    Inspiring
    May 15, 2009

    Without seeing the code or anything :

    - each new browser request will initialize the component

    - each <cfinvoke> tag will also initialize the component

    If you want to keep the modified value(component ?) over the entire session, you could cach the component in the SESSION scope by using the CreateObject function and using it from there on.

    Cheers,

    Bert.

    Known Participant
    May 15, 2009

    thank you for your response


    from cfform

          <cfinput type="text" class="textboxies" name="member_addr"autosuggest=
                                "cfc:components/suggestcfc.getodo({cfautosuggestvalue},{member_nomos},{member_area})">

    from suggestcfc.cfc

    <cfcomponent>

         <cfset variables.prevtk='00000'>

    <cffunction name="getodo" access="remote" returntype="array" output="false">

            <cfargument name="suggestvalue" required="true">
            <cfargument name="filternomos" type="numeric" required="true">
             <cfargument name="filterarea" type="numeric" required="true">
            <cfset var myarray = ArrayNew(1)>
           
            <cfquery name="gettk" datasource="pasent_db" username="root" password="test">
                SELECT str FROM streets
                WHERE muni= #ARGUMENTS.filterarea# and nomos=#ARGUMENTS.filternomos#
                and str LIKE <cfqueryparam value="#suggestvalue#%" cfsqltype="cf_sql_varchar">
            </cfquery>
           
            <cfloop query="gettk">
                <cfset arrayAppend(myarray, str)>
            </cfloop>
           
            <cfreturn myarray>
        </cffunction>
       
       
       
       
        <cffunction name="gettk" access="remote" returntype="any" output="no">

             <cfargument name="filternomos" type="numeric" required="true">
            <cfargument name="filterarea" type="numeric" required="true">
            <cfargument name="filterodos" type="string" required="true">       
           
            <cfquery name="gettk" datasource="pasent_db" username="root" password="test">
                SELECT tk FROM streets
                WHERE nomos=#ARGUMENTS.filternomos# and muni=#ARGUMENTS.filterarea# and
                str='#ARGUMENTS.filterodos#'
            </cfquery>
           
           
            <Cfif #len(gettk.tk)# gt 0>
                <cfset  remembertk(gettk.tk)>
                <cfreturn variables.prevtk>
            <cfelse>
                <cfreturn variables.prevtk>
            </Cfif>

        </cffunction>
       
         <cffunction name="remembertk" access="remote" returnType="void">
            <cfargument name="tk" type="string" required="true">

                 <cfset variables.prevtk=tk>
                <cfreturn>
               
         </cffunction>

    <cfcomponent>

    All i  want to do is that if the query of the gettk returns 0 records i wish for the function to return its previous value, or just do nothing.. i havent found way for the later. so i figured this way instead.