[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

Weird Issue with the instance data of a CFC

The CFC is quite long, so I won't post all of it.

The problem is that when I dump the CFC any of the "bind" variables do not appear, and when I try to set for example this.bind.type = "whatever"; it throws me a weird error saying only "TYPE" - no its not a reserved word, as its a structure, even when I remove it this.bind.source gives the same problem... Anyone, please....

<cfcomponent
      displayname="Object"
      hint="Every Object extends on this Base Object, it returns information about the Object itself, for example; Function collection, Property collection, Object name etc. It also Binds every Object to its data storage or provider."
      output="false"
      author="Taco Fleur (taco@coldfusionist.com)">
      <!---
      Define: Is A
      An Object is a Class
      Define: Has A
      An Object has a Property
      An Object has a Method
      An Object has an Extension
       --->

      <!--- Declare properties for this Object --->
      <cfproperty
            name="this.event"
            type="string"
            access="private"
            displayname="Object Action"
            hint="Holds the Event of the Object."
            required="true"
            regularexpression="new|insert|list|view|edit|update|delete" />
      <cfproperty
            name="this.objectRoot"
            access="private"
            type="string"
            displayname="Object Root"
            hint="Holds the Root to the Object Path."
            required="true" />
      <cfproperty
            name="this.composed"
            access="private"
            type="struct"
            displayname="Composed"
            hint="Holds any Composed Objects."
            required="false" />
      <cfproperty
            name="this.bind"
            access="private"
            type="struct"
            displayname="Bind"
            hint="Holds the information to Bind this Object to its Data or Storage."
            required="true" />
      <cfproperty
            name="this.bind.type"
            access="private"
            type="struct"
            displayname="Bind Type"
            hint="Holds the Bind Type information, valid types are; datasource, http call, file or variable."
            required="true"
            regularexpression="datasource|httpCall|file|variable" />
      <cfproperty
            name="this.bind.source"
            access="private"
            type="struct"
            displayname="Bind Source"
            hint="Holds the Bind Source information, valid sources are; datasource name, URI, path to file or variable name."
            required="true" />

      <cfproperty
            name="this.meta"
            access="private"
            type="struct"
            displayname="Objects Meta"
            hint="Holds the Meta Data of the Object"
            required="false" />


      <cfscript>
      this.event = "";
      this.objectRoot = "";
      this.composed = structNew();
      // An Objects binds to something;
      // when Action is "new" it can bind to a datasource, http call, variable or file to receive its pre-populated data
      // when Action is "insert" it can bind to a form, datasource, http call, variable or file to receive its data to insert
      // when Action is "list" it can bind to a datasource, http call, variable or file to receive its data to list
      // when Action is "view" it can bind to a form, datasource, http call, variable or file to receive its data to list
      // when Action is "edit" it can bind to a datasource, http call, variable or file to receive its data to edit
      // when Action is "update" it can bind to a form, datasource, http call, variable or file to receive its data to edit
      // when Action is "delete" it can bind to a variable, datasource, http call or file to receive its identity for the row to delete
      this.bind = structNew();
      // Valid bind types are form, datasource, http call, file or variable
      this.bind.type = "";
      // Valid sources are datasource name, URI, path to file or variable name
      this.bind.source = "";
      // Username to access source, if required
      this.bind.username = "";
      // Password to access source, if required
      this.bind.password = "";
      // Delimiter used in source
      this.bind.delimiter = "";
      // The Object that provides the interface to the data **** Still need to create a cfproperty for this var
      this.bind.object = "";
0
Tacobell777
Asked:
Tacobell777
  • 5
1 Solution
 
mosphatCommented:
What exactly are you doing with the component? Just a createobject() and then dump it? If so, I'd like to see the rest of the component, since the part you provided seems to work fine.
0
 
MauseCommented:
Hi Taco

Tried your cfc and had no problem creating it, browse it or dump it
Doesn't give the error you more information? (line number??)
are you sure the error is about  this.bind.type ?

Mause
0
 
Tacobell777Author Commented:
I'll post the rest tomorrow, not at work now.

Weird that it works, the whole error is weird though, it doesn't give me much info to go on.

The problem is with this.bind.type and when I remove it the problem is with the next this.bind and so on.. but only with this.bind
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Tacobell777Author Commented:
ok, here it is, its big..

Object.cfc *****************
<cfcomponent
      displayname="Object"
      hint="Every Object extends on this Base Object, it returns information about the Object itself, for example; Function collection, Property collection, Object name etc. It also Binds every Object to its data storage or provider."
      output="false"
      author="Taco Fleur (taco@coldfusionist.com)">
      <!---
      Define: Is A
      An Object is a Class
      Define: Has A
      An Object has a Property
      An Object has a Method
      An Object has an Extension
       --->

      <!--- Declare properties for this Object --->
      <cfproperty
            name="this.event"
            type="string"
            access="private"
            displayname="Object Action"
            hint="Holds the Event of the Object."
            required="true"
            regularexpression="new|insert|list|view|edit|update|delete" />
      <cfproperty
            name="this.objectRoot"
            access="private"
            type="string"
            displayname="Object Root"
            hint="Holds the Root to the Object Path."
            required="true" />
      <cfproperty
            name="this.composed"
            access="private"
            type="struct"
            displayname="Composed"
            hint="Holds any Composed Objects."
            required="false" />
      <cfproperty
            name="this.bind"
            access="private"
            type="struct"
            displayname="Bind"
            hint="Holds the information to Bind this Object to its Data or Storage."
            required="true" />
      <cfproperty
            name="this.bind.type"
            access="private"
            type="struct"
            displayname="Bind Type"
            hint="Holds the Bind Type information, valid types are; datasource, http call, file or variable."
            required="true"
            regularexpression="datasource|object|httpCall|file|variable" />
      <cfproperty
            name="this.bind.source"
            access="private"
            type="struct"
            displayname="Bind Source"
            hint="Holds the Bind Source information, valid sources are; datasource name, path to object, URI, path to file or variable name."
            required="true" />

      <cfproperty
            name="this.meta"
            access="private"
            type="struct"
            displayname="Objects Meta"
            hint="Holds the Meta Data of the Object"
            required="false" />


      <cfscript>
      this.event = "";
      this.objectRoot = "";
      this.composed = structNew();
      // An Objects binds to something;
      // when Action is "new" it can bind to a datasource, http call, variable or file to receive its pre-populated data
      // when Action is "insert" it can bind to a form, datasource, http call, variable or file to receive its data to insert
      // when Action is "list" it can bind to a datasource, http call, variable or file to receive its data to list
      // when Action is "view" it can bind to a form, datasource, http call, variable or file to receive its data to list
      // when Action is "edit" it can bind to a datasource, http call, variable or file to receive its data to edit
      // when Action is "update" it can bind to a form, datasource, http call, variable or file to receive its data to edit
      // when Action is "delete" it can bind to a variable, datasource, http call or file to receive its identity for the row to delete
      this.bind = structNew();
      // Valid bind types are form, datasource, http call, file or variable
      this.bind.type = "";
      // Valid sources are datasource name, URI, path to file or variable name
      this.bind.source = "";
      // Username to access source, if required
      this.bind.username = "";
      // Password to access source, if required
      this.bind.password = "";
      // Delimiter used in source
      this.bind.delimiter = "";
      // The Object that provides the interface to the data **** Still need to create a cfproperty for this var
      this.bind.object = "";

      // Variable will hold the Meta data for the object
      // We do not populate this data upon instantiation of the object because it is to resource hogging
      //
      // We need to access the Object Meta Data;
      // when Action is "new" to create a form to capture Data, if the form is not cached
      // when Action is "insert" to validate data
      // when Action is "edit" to create a form to allow editing of Data, if the form is not cached
      // when Action is "update" to validate data
      this.meta = structNew();
      // Variable will hold the instance data of the Object
      this.instance = structNew();
      </cfscript>


      <cffunction
            name="init"
            access="public"
            returntype="Object">

            <cfargument
                  name="event"
                  type="string"
                  required="yes"
                  displayname="Event"
                  hint="Event of the Object" />
            <cfargument
                  name="objectRoot"
                  type="string"
                  required="yes"
                  displayname="Object Root"
                  hint="Path to the Object Root" />
            <cfargument
                  name="bind"
                  type="struct"
                  required="yes"
                  displayname="Bind"
                  hint="Bind information for the Object" />

            <cfscript>
            this.event = arguments.event;
            // The Root to the Class folder
            this.objectRoot = arguments.objectRoot;
            // Set Bind information
            this.bind.type = arguments.bind.type;
            // Valid sources are datasource name, URI, path to file or variable name
            this.bind.source = arguments.bind.source;
            // Username to access source, if required
            this.bind.username = getBindUsername( arguments.bind );
            // Password to access source, if required
            this.bind.password = getBindPassword( arguments.bind );
            // Delimiter used in source
            this.bind.delimiter = getBindDelimiter( arguments.bind );

            // Return the instance of the Object
            return this;
            </cfscript>

      </cffunction>


      <cffunction
            access="public"
            name="getPropertyCollection"
            output="false"
            returntype="struct"
            displayname="Get Property Collection"
            hint="Returns a structure containing all Properties in this Object.">
            <cfargument
                  name="access"
                  type="string"
                  required="no"
                  displayname="Access"
                  hint="Return only properties with Access value of" />

            <cfscript>
            // Check if the Object Meta Data is set
            if ( NOT isObjectMetaDataSet() )
            {
                  // Set the Object Meta Data
                  setObjectMetaData();
            }

            // Check if the Property Composition exists
            if ( NOT isComposed( "Property" ) )
            {
                  // Create a Composition of the Property Object
                  compose( objectPath = this.objectRoot & ".object.Property" );
                  this.composed.Property.init( getObjectMetaData() );
            }
            </cfscript>

            <cfreturn this.composed.Property.getPropertyCollection() />            

      </cffunction>


      <cffunction
            access="public"
            name="getMethodCollection"
            output="false"
            returntype="struct"
            displayname="Get Method Collection"
            hint="Returns a structure containing all Methods in this Object.">

            <cfscript>
            // Check if the Object Meta Data is set
            if ( NOT isObjectMetaDataSet() )
            {
                  // Set the Object Meta Data
                  setObjectMetaData();
            }

            // Check if the Property Composition exists
            if ( NOT isComposed( "Method" ) )
            {
                  // Create a Composition of the Property Object
                  compose( objectPath = this.objectRoot & ".object.Method" );
                  this.composed.Method.init( getObjectMetaData() );
            }
            </cfscript>

            <cfreturn this.composed.Method.getMethodCollection() />            

      </cffunction>


      <cffunction
            access="public"
            name="getObjectMetaData"
            output="false"
            returntype="struct"
            displayname="Get Object Meta Data"
            hint="Returns the Meta Data for this Object.">

            <cfscript>
            return this.meta;
            </cfscript>

      </cffunction>


      <cffunction
            access="public"
            name="getObjectName"
            output="false"
            returntype="string"
            displayname="Get Object Name"
            hint="Returns the Name for this Object.">

            <cfscript>
            // Check if the Object Meta Data is set
            if ( NOT isObjectMetaDataSet() )
            {
                  // Set the Object Meta Data
                  setObjectMetaData();
            }
            
            return this.meta.name;
            </cfscript>

      </cffunction>


      <cffunction
            access="public"
            name="getObjectFriendlyName"
            output="false"
            returntype="string"
            displayname="Get Object Friendly Name"
            hint="Returns the Friendly Name for this Object.">

            <cfscript>
            // Check if the Object Meta Data is set
            if ( NOT isObjectMetaDataSet() )
            {
                  // Set the Object Meta Data
                  setObjectMetaData();
            }
            
            return this.meta.displayName;
            </cfscript>

      </cffunction>


      <cffunction
            access="public"
            name="getObjectPath"
            output="false"
            returntype="string"
            displayname="Get Object Path"
            hint="Returns the Path for this Object.">

            <cfscript>
            // Check if the Object Meta Data is set
            if ( NOT isObjectMetaDataSet() )
            {
                  // Set the Object Meta Data
                  setObjectMetaData();
            }
            
            return this.meta.path;
            </cfscript>

      </cffunction>


      <cffunction
            access="public"
            name="getObjectHint"
            output="false"
            returntype="string"
            displayname="Get Object Hint"
            hint="Returns the Hint for this Object.">

            <cfscript>
            // Check if the Object Meta Data is set
            if ( NOT isObjectMetaDataSet() )
            {
                  // Set the Object Meta Data
                  setObjectMetaData();
            }
            
            return this.meta.hint;
            </cfscript>

      </cffunction>


      <cffunction
            access="public"
            name="getBindUsername"
            output="false"
            returntype="string"
            displayname="Get Bind Username"
            hint="Returns the Username form the Bind structure, if present.">

            <cfargument
                  name="bind"
                  type="struct"
                  required="yes"
                  displayname="Bind"
                  hint="Bind information for the Object" />

            <cfif structKeyExists( arguments.bind, "username" )>
                  <cfreturn arguments.bind.username />
            <cfelse>
                  <cfreturn "" />
            </cfif>

      </cffunction>


      <cffunction
            access="public"
            name="getBindPassword"
            output="false"
            returntype="string"
            displayname="Get Bind Password"
            hint="Returns the Password from the Bind structure, if present.">

            <cfargument
                  name="bind"
                  type="struct"
                  required="yes"
                  displayname="Bind"
                  hint="Bind information for the Object" />

            <cfif structKeyExists( arguments.bind, "password" )>
                  <cfreturn arguments.bind.password />
            <cfelse>
                  <cfreturn "" />
            </cfif>

      </cffunction>


      <cffunction
            access="public"
            name="getBindDelimiter"
            output="false"
            returntype="string"
            displayname="Get Bind Delimiter"
            hint="Returns the Delimiter from the Bind structure, if present.">

            <cfargument
                  name="bind"
                  type="struct"
                  required="yes"
                  displayname="Bind"
                  hint="Bind information for the Object" />

            <cfif structKeyExists( arguments.bind, "delimiter" )>
                  <cfreturn arguments.bind.delimiter />
            <cfelse>
                  <cfreturn "" />
            </cfif>

      </cffunction>


      <cffunction
            access="public"
            name="getInstance"
            output="false"
            displayname="Get Instance"
            hint="Returns the Instane Data of the Object.">

            <cfreturn this.instance />

      </cffunction>


      <cffunction
            access="public"
            name="setObjectMetaData"
            output="false"
            displayname="Set Object Meta Data"
            hint="Sets the Meta Data of the Object to this.meta.">

            <cfset this.meta = getMetaData( this ) />

      </cffunction>


      <cffunction
            access="private"
            name="isObjectMetaDataSet"
            output="false"
            returntype="boolean"
            displayname="Is Object Meta Data Set"
            hint="Returns whether the Object Meta Data is set in this.meta.">

            <cfif structKeyExists( this.meta, "type" )>
                  <cfreturn true />
            <cfelse>
                  <cfreturn false />
            </cfif>

      </cffunction>


      <cffunction
            access="private"
            name="isExtended"
            output="false"
            returntype="boolean"
            displayname="Is Extended"
            hint="Returns whether the Object or is Extended.">

            <cfargument
                  name="object"
                  type="struct"
                  required="yes">

            <cfif structKeyExists( arguments.object, "extends" )>
                  <cfreturn true />
            <cfelse>
                  <cfreturn false />
            </cfif>

      </cffunction>


      <cffunction
            access="private"
            name="isComposed"
            output="false"
            returntype="boolean"
            displayname="Is Composed"
            hint="Returns whether the Object is Composed.">

            <cfargument
                  name="object"
                  type="string"
                  required="yes">

            <cfif structKeyExists( this.composed, arguments.object )>
                  <cfreturn true />
            <cfelse>
                  <cfreturn false />
            </cfif>

      </cffunction>


      <cffunction
            access="private"
            name="hasProperty"
            output="false"
            returntype="boolean"
            displayname="Has Property"
            hint="Returns whether the current Object or Child Object has Properties.">

            <cfargument
                  name="object"
                  type="struct"
                  required="yes">

            <cfif structKeyExists( arguments.object, "properties" )>
                  <cfreturn true />
            <cfelse>
                  <cfreturn false />
            </cfif>

      </cffunction>


      <cffunction
            access="private"
            name="compose"
            output="false"
            returntype="void"
            displayname="Compose"
            hint="Composes an Object">

            <cfargument
                  name="objectPath"
                  type="string"
                  required="yes">

            <cfscript>
            structInsert( this.composed, listLast( arguments.objectPath, "." ), createObject( "component", arguments.objectPath ), true );
            </cfscript>

      </cffunction>

      <cffunction
            access="public"
            name="store"
            output="false"
            returntype="numeric"
            displayname="Store"
            hint="Stores an Object in Object Storage defined by this.bind">

            <cfset abstractMethodCalled() />

            <cfreturn qStore.identityValue />

      </cffunction>


      <cffunction
            access="public"
            name="update"
            output="false"
            returntype="void"
            displayname="Update"
            hint="Updates an Object in Object Storage defined by this.bind">

            <cfset abstractMethodCalled() />

      </cffunction>


      <cffunction
            access="public"
            name="delete"
            output="false"
            returntype="void"
            displayname="Delete"
            hint="Deletes an Object in Object Storage defined by this.bind">

            <cfset abstractMethodCalled() />

      </cffunction>


      <cffunction
            access="public"
            name="bind"
            output="false"
            returntype="void"
            displayname="Bind"
            hint="Binds the Object to its Data Storage">

            <cfswitch expression="#this.bind.type#">
                  <cfcase value="datasource">
                        <cfset this.bind.object = createObject( "component", this.objectRoot & "database.QueryInterface" ) />
                  </cfcase>
                  <cfcase value="object">
                        <cfset this.bind.object = createObject( "component", this.bind.source ) />
                  </cfcase>
                  <cfcase value="httpCall">
                        <cfset this.bind.object = createObject( "component", this.objectRoot & "http.QueryInterface" ) />
                  </cfcase>
                  <cfcase value="file">
                        <cfset this.bind.object = createObject( "component", this.objectRoot & "fileSystem.QueryInterface" ) />
                  </cfcase>
                  <cfcase value="variable">
                  
                  </cfcase>
            </cfswitch>

      </cffunction>


      <cffunction
            access="private"
            name="abstractMethodCalled"
            output="false"
            returntype="void"
            displayname="Abstract Method Called"
            hint="Throws an Error when an Abstract Method is called">

            <cfthrow
                  message="This Method is Abstract and must be overridden - Object: #getObjectName()#"
                  type="AbstractMethodNotOverriden" />

      </cffunction>


</cfcomponent>

Employee.cfc ****

<cfcomponent
      extends="frameWork_development._resource.class.Object"
      displayname="Employee"
      output="false">

      <!---
      Define: Is A

      Define: Has A
       --->

      <!--- Declare properties for this Object --->
      <cfproperty
            name="idEmployee"
            access="protected"
            type="numeric"
            displayname="Identity"
            hint=""
            regularexpression="[^0-9]" />
      <cfproperty
            name="firstName"
            access="public"
            type="string"
            lengthminimum="2"
            lengthmaximum="40"
            displayname="First Name"
            hint=""
            required="true" />
      <cfproperty
            name="lastName"
            access="public"
            type="string"
            lengthminimum="2"
            lengthmaximum="40"
            displayname="Last Name"
            hint=""
            required="true" />
      <cfproperty
            name="dateOfBirth"
            access="public"
            type="date"
            displayname="Date Of Birth"
            allowed="0-9/"
            formatexample="00/00/00"
            required="true" />

      <!--- Create instance variables --->
      <cfscript>
      this.instance.idEmployee = "";
      this.instance.firstName = "";
      this.instance.lastName = "";
      this.instance.dateOfBirth = "";
      </cfscript>


      <cffunction
            name="init"
            access="public"
            returntype="Employee">

            <cfargument
                  name="event"
                  type="string"
                  required="yes"
                  default="initialize" />
            <cfargument
                  name="objectRoot"
                  type="string"
                  required="yes" />
            <cfargument
                  name="bind"
                  type="struct"
                  required="no" />
            <cfargument
                  name="idEmployee"
                  required="no"
                  default="" />
            <cfargument
                  name="firstName"
                  required="no"
                  default="" />
            <cfargument
                  name="lastName"
                  required="no"
                  default="" />
            <cfargument
                  name="dateOfBirth"
                  required="no"
                  default="" />

            <cfscript>
            super.init( arguments.event, arguments.objectRoot, arguments.bind );
            this.instance.idEmployee = arguments.idEmployee;
            this.instance.firstName = arguments.firstName;
            this.instance.lastName = arguments.lastName;
            this.instance.dateOfBirth = arguments.dateOfBirth;
            </cfscript>

            <cfswitch
                  expression="#this.event#">
                  <!--- The following actions require an instance of the Scheduler Data to be present: edit, view, delete, run --->
                  <cfcase value="edit,view,delete,run">
                        <cfset structAppend( this.data, getInstance( identity = arguments.pkIDSchedule ), true ) />
                  </cfcase>
            </cfswitch>      

            <cfreturn this />

      </cffunction>


      <cffunction
            access="public"
            name="setInstance"
            output="false"
            returntype="struct">

            <cfargument
                  name="identity"
                  type="numeric"
                  required="yes" />

            <cfset var result = structNew() />

            <cfset result = queryToStructure( this.composed.queryInterface.getRecordByIdentity( arguments.identity ) ) />

            <cfreturn result />

      </cffunction>


      <cffunction
            access="public"
            name="setIdentity"
            output="false"
            returntype="void">

            <cfargument
                  name="identity"
                  type="numeric"
                  required="yes" />

            <cfset this.data.idEmployee = arguments.identity />

      </cffunction>


      <cffunction
            access="public"
            name="setFirstName"
            output="false"
            returntype="void">

            <cfargument
                  name="firstName"
                  type="string"
                  required="yes" />

            <cfset this.instance.firstName = arguments.firstName />

      </cffunction>


      <cffunction
            access="public"
            name="setLastName"
            output="false"
            returntype="void">

            <cfargument
                  name="lastName"
                  type="string"
                  required="yes" />

            <cfset this.instance.lastName = arguments.lastName />

      </cffunction>


      <cffunction
            access="public"
            name="setDateOfBirth"
            output="false"
            returntype="void">

            <cfargument
                  name="dateOfBirth"
                  type="string"
                  required="yes" />

            <cfset this.instance.dateOfBirth = arguments.dateOfBirth />

      </cffunction>


</cfcomponent>

***** this is the actual error

TYPE  
 
 
The error occurred in D:\Inetpub\wwwroot\internet\development\framework\_resource\class\Object.cfc: line 139
Called from D:\Inetpub\wwwroot\internet\development\framework\company\Employee\Employee.cfc: line 92
Called from D:\Inetpub\wwwroot\internet\development\framework\company\Employee\new\act_new.cfm: line 18
Called from D:\Inetpub\wwwroot\internet\development\framework\company\Employee\new\dsp_index.cfm: line 8
Called from D:\Inetpub\wwwroot\internet\development\framework\app_layout.cfm: line 12
Called from D:\Inetpub\wwwroot\internet\development\framework\company\Employee\new\OnRequestEnd.cfm: line 6
 
137 :             this.objectRoot = arguments.objectRoot;
138 :             // Set Bind information
139 :             this.bind.type = arguments.bind.type;
140 :             // Valid sources are datasource name, URI, path to file or variable name
141 :             this.bind.source = arguments.bind.source;

 
0
 
Tacobell777Author Commented:
PS. here is the code to instantiate the object

<cfscript>
// Create the Object
obj = createObject( "component", "#request.object#" );
// Initialize the Object
bind = structNew();
bind.type = "datasource";
bind.source = "dsnTest";
obj.init( event = request.method, objectRoot = application.setting.objectRoot, bind = variables.bind );
</cfscript>
0
 
Tacobell777Author Commented:
obj = createObject( "component", "#request.object#" ); should be
obj = createObject( "component", "Employee" );
0
 
Tacobell777Author Commented:
got it, bind is also a function name...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now