Why don't my component properties update?


i try make short possible.  have component looks this:

 

<cfcomponent extends = "path.to.base" output = "false">

 

     <cfproperty type="string" name="id" />

     <cfset variables.my = {} />

     <cfset variables.my.id = '' />

 

     <cffunction access="public" returntype="path.to.component" name="init" output="false">

          <cfargument required="false" type="string" name="id" default="" />

          <cfset setproperty( 'id', arguments.id ) />

          <cfreturn />

     </cffunction>

 

</cfcomponent>

 

the setproperty() method exists in extended 'path.to.base' component.  looks this:

 

<cffunction access="public" returntype="boolean" name="setproperty" output="false">

 

     <cfargument required="true" type="string" name="propertyname" />

     <cfargument required="true" type="any" name="propertyvalue" />

 

     <cfset variables.my[ arguments.propertyname ] = arguments.propertyvalue />

 

     <cfreturn true />

 

</cffunction>

 

i using onmissingmethod() in path.to.base component allows me call properties myobj.id() (and since id method not exist, checks if 'id' exists in variables.my, , if so, returns it.  so, have code this:

 

<cfset myobj = new path.to.component( '12345' ) />

<cfdump var="#myobj.id()#" />

<cfset myobj.setproperty( 'id', '54321' ) />

<cfdump var="#myobj.id()#" />

<cfdump var="#myobj#" />

 

line 2 outputs: '12345' (expected)

line 4 outputs: '54321' (expected)

line 5 dumps object, , has methods exepcted, , properties substructure, id key, value empty.

 

so question "why coldfusion not updating respective property, though updating in private variables.my keys?

to start with, think not practice set or update component's instance variables means of arbitrary methods have done. use 'setter' method set instance variables. way, if empty string during debugging, know setter method had not been called. should "var" methods' variables. however, issue report caused else.

 

coldfusion stores methods variables, too. in opinion, when give same name property , method, place coldfusion in ambiguous situation. change name of method in path.to.base component 'id' 'getid'.



More discussions in ColdFusion


adobe

Comments

Popular posts from this blog

Could not place because the source rectangle is empty

Thread: Using smartcard reader with vpnc

Adobe Font Folio 7.0 or just 7?