User Guide Cancel

cfproperty

 

Description

Defines properties and their annotations for a ColdFusion component (CFC). The properties are used to create complex data types for web services, while the annotations are used to define Object Relational Model (ORM) for a CFC. The attributes of this tag are exposed as component metadata and are subject to inheritance rules.

Category

Syntax

<cfproperty
name="name"
default="default value"
displayname="descriptive name"
hint="extended description"
required="false|true"
serializable="true|false"
type="type">
<cfproperty name="name" default="default value" displayname="descriptive name" hint="extended description" required="false|true" serializable="true|false" type="type">
<cfproperty 
name="name" 
default="default value" 
displayname="descriptive name" 
hint="extended description" 
required="false|true" 
serializable="true|false" 
type="type">
Note:

For ORM-related attributes and their usage, see Map the properties in the Developing ColdFusion Applications.

See also

cfargumentcfcomponentcffunctioncfinvokecfinvokeargumentcfobjectcfreturnDocumenting CFCs in Building and Using ColdFusion Components, Implicit Get and Set Functions in the Developing ColdFusion Applications

History

  • ColdFusion (2025 release): The default value of cfproperty can be CFML expressions. In this release , the default value of a cfproperty can be expressions. In earlier versions, only string values were allowed.
  • ColdFusion 9: Added attributes for defining Object Relational Model for the CFC.Added implicit getters and setters. Added validate and validateparams attributes.
  • ColdFusion MX: Added this tag.

Attributes

Attribute

Req/Opt

Default

Description

batchsize

 

 

For information about these attributes, see ColdFusion ORM.

cascade

 

 

 

catalog

 

 

 

cfc

 

 

 

collectiontype

 

 

 

column

 

 

 

constrained

 

 

 

datatype

 

 

 

default

Optional

 

This attribute allows a valid CFML expression. See the example below for more information.

If no property value is set when the component is used for a web service, specifies a default value. If this attribute is present, the required attribute must be set to no or not specified.
For ORM-specific usage of the default attribute, see ColdFusion ORM.

displayname

Optional

 

A value to be displayed when using introspection to show information about the CFC. The value appears in parentheses following the property name.

dynamicInsert

 

 

For information about these attributes, see ColdFusion ORM.

dynamicupdate

 

 

 

elementColumn

 

 

 

elementtype

 

 

 

entityname

 

 

 

fetchbatchsize

 

 

 

fieldType

 

 

 

fkcolumn

 

 

 

formula

 

 

 

generator

 

 

 

getter

Optional

 

Specifies whether to generate getter methods or not. Value are:

  • true
  • false

hint

Optional

 

Text to be displayed when using introspection to show information about the CFC. This attribute can be useful for describing the purpose of the parameter.

index

 

 

For information about these attributes, see ColdFusion ORM.

insert

 

 

 

inverse

 

 

 

 

inversejoincolumn

 

 

 

 

joincolumn

 

 

 

lazy

 

 

 

length

 

 

 

linkcatalog

 

 

 

linkschema

 

 

 

linktable

 

 

 

mappedby

 

 

 

missingrowIgnored

 

 

 

name

Required

 

A string; a property name. Must be a static value.

notnull

 

 

For information about these attributes, see ColdFusion ORM.

optimisticLock

 

 

 

optimisticLockgenerated

 

 

 

orderby

 

 

 

orderByreadonly

 

 

 

params

 

 

For information about these attributes, see ColdFusion ORM.

persistent

 

 

 

preceision

 

 

 

readonly

 

 

 

readonly

 

 

 

required

Optional

no

Whether the parameter is required:

  • yes
  • no

rowid

 

 

For information about these attributes, see ColdFusion ORM.

scale

 

 

 

 

setter

 

 

 

Specifies whether to generate setter methods or not. Possible values are:

  • true
  • false

schema

 

 

For information about these attributes, see ColdFusion ORM.

selectbeforeupdate

 

 

 

selectkey

 

 

 

sequence

 

 

 

serializable

Optional

true

Specifies whether this property can be serialized. If you set this value to false, the property cannot be serialized, so any changes made are not retained on session replication, and the property has its default value (if any) on the second server. Use this attribute to prevent serializaton of properties in CFCs that are serializable.

source

 

 

For information about these attributes, see ColdFusion ORM.

structkeycolumn

 

 

 

structkeycolumn

 

 

 

structkeydatatype

 

 

 

structkeyType

 

 

 

table

 

 

 

table

 

 

 

type

Optional

any

A string; identifies the property data type:

  • any
  • array
  • binary
  • boolean
  • date
  • guid: the argument must be a UUID or GUID of the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx where each x is a character representing a hexadecimal number (0-9A-F).
  • numeric
  • query
  • string
  • struct
  • uuid: The argument must be a ColdFusion UUID of the form xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx where each x is a character representing a hexadecimal number (0-9A-F).
  • variableName: a string formatted according to ColdFusion variable naming conventions.
  • a component name: if the type attribute value is not one of the preceding items, ColdFusion treats it as the name of a ColdFusion component. When the function executes, it generates an error if the argument that is passed in is not a CFC with the specified name.

unique

 

 

For information about these attributes, see ColdFusion ORM.

uniquekey

 

 

 

update

 

 

 

 

where

 

 

 

 

validate

Optional

 

For more information, see Validate and validateparams attributes in Functions.

validateparam

Optional

 

 

Usage

You must position cfproperty tags at the beginning of a component, above executable code and function definitions. If a component is not used as a web service, <cfproperty> only provides metadata information of the property. It does not define variables or set values that you can use in your component. However, it creates implicit setters and getters for the property in the CFC depending on whether getter/setter attributes are enabled. For details, see Implicit Get and Set Functions in Developing ColdFusion Applications.
For Object Relational Model (ORM), cfproperty is used to define relational mapping for the property of the CFC. For details, see ColdFusion ORM in Developing ColdFusion Applications.
For web services that you create in ColdFusion, the cfproperty tag defines complex variables used by the web service.

Example

The following code defines a component in the file address.cfc that contains properties that represent a street address:

<cfcomponent>
<cfproperty name="Number" type="numeric">
<cfproperty name="Street" type="string">
<cfproperty name="City" type="string">
<cfproperty name="State" type="string">
<cfproperty name="Country" type="string">
</cfcomponent>
<cfcomponent> <cfproperty name="Number" type="numeric"> <cfproperty name="Street" type="string"> <cfproperty name="City" type="string"> <cfproperty name="State" type="string"> <cfproperty name="Country" type="string"> </cfcomponent>
<cfcomponent> 
<cfproperty name="Number" type="numeric"> 
<cfproperty name="Street" type="string"> 
<cfproperty name="City" type="string"> 
<cfproperty name="State" type="string"> 
<cfproperty name="Country" type="string"> 
</cfcomponent>

This component represents a complex data type that can be used in a component that is exported as a web service, such as the following:

<cfcomponent>
<cffunction name="echoAddress" returnType="address" access="remote">
<cfargument name="input" type="address">
<cfreturn arguments.input>
</cffunction>
</cfcomponent>
<cfcomponent> <cffunction name="echoAddress" returnType="address" access="remote"> <cfargument name="input" type="address"> <cfreturn arguments.input> </cffunction> </cfcomponent>
<cfcomponent> 
<cffunction name="echoAddress" returnType="address" access="remote"> 
<cfargument name="input" type="address"> 
<cfreturn arguments.input> 
</cffunction> 
</cfcomponent>

Example 1

myprops.cfc

component accessors=true {
property name="testProp" default="test";
property name="propA" default="#[1,2,3]#";
property name="proph" type="array" default="[1,2,3].avg()";
property name="prope" type="array" default="#ArrayNew(1)#";
property name="propAA" type="any" default="#['key1':'val1']#";
property name="propF" type="struct" default="#{"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,}.append({ "id": "5001", "type": "None" })#" ;
property name="propV" type="any" default="# tval? (tval ? 'trueValue' : 'falseVal') : 'falseValue'#";
property name="propW" type="any" default="#UCase("This is a text: ") & ToString(123 + 456)#";
property name="propX" default="#fval?: 'true'#";
property name="propY" type="any" default="#originalStruct?.address?.street#";
property name="propZ" type="any" default="#originalStruct ?? 'notnullvalue'#";
property name="propAB" type="any" default=#IsStruct(originalStruct) === true#;
property name="propS" type="any" default="#x LTE y#";
property name="propK" type="string" default="#str contains substr#";
property name="propT" type="any" default="#str does not contain substr#";
x=25;
y=5*5;
originalStruct = {name = "Alice", address = {street = "123 Main St", city = "Wonderland"},
mobile = 7777777777,};
str ='Adobe'
substr= 'Ad'
tval=true
fval=false
}
component accessors=true { property name="testProp" default="test"; property name="propA" default="#[1,2,3]#"; property name="proph" type="array" default="[1,2,3].avg()"; property name="prope" type="array" default="#ArrayNew(1)#"; property name="propAA" type="any" default="#['key1':'val1']#"; property name="propF" type="struct" default="#{"id": "0001", "type": "donut", "name": "Cake", "ppu": 0.55,}.append({ "id": "5001", "type": "None" })#" ; property name="propV" type="any" default="# tval? (tval ? 'trueValue' : 'falseVal') : 'falseValue'#"; property name="propW" type="any" default="#UCase("This is a text: ") & ToString(123 + 456)#"; property name="propX" default="#fval?: 'true'#"; property name="propY" type="any" default="#originalStruct?.address?.street#"; property name="propZ" type="any" default="#originalStruct ?? 'notnullvalue'#"; property name="propAB" type="any" default=#IsStruct(originalStruct) === true#; property name="propS" type="any" default="#x LTE y#"; property name="propK" type="string" default="#str contains substr#"; property name="propT" type="any" default="#str does not contain substr#"; x=25; y=5*5; originalStruct = {name = "Alice", address = {street = "123 Main St", city = "Wonderland"}, mobile = 7777777777,}; str ='Adobe' substr= 'Ad' tval=true fval=false }
component accessors=true {
        property name="testProp" default="test";
        property name="propA" default="#[1,2,3]#";
        property name="proph" type="array" default="[1,2,3].avg()";
        property name="prope" type="array" default="#ArrayNew(1)#";   

        property name="propAA" type="any" default="#['key1':'val1']#"; 
        property name="propF" type="struct" default="#{"id": "0001",
            "type": "donut",
            "name": "Cake",
            "ppu": 0.55,}.append({ "id": "5001", "type": "None" })#" ;

        property name="propV" type="any" default="# tval? (tval ? 'trueValue' : 'falseVal') : 'falseValue'#";
        property name="propW" type="any" default="#UCase("This is a text: ") & ToString(123 + 456)#";

        property name="propX" default="#fval?: 'true'#";
        property name="propY" type="any" default="#originalStruct?.address?.street#";
        property name="propZ" type="any" default="#originalStruct ?? 'notnullvalue'#";

        property name="propAB" type="any" default=#IsStruct(originalStruct) === true#;
        property name="propS" type="any" default="#x LTE y#";

        property name="propK" type="string" default="#str contains substr#";
        property name="propT" type="any" default="#str does not contain substr#";


        x=25;
        y=5*5;
        originalStruct = {name = "Alice", address = {street = "123 Main St", city = "Wonderland"}, 
        mobile = 7777777777,};

        str ='Adobe'
        substr= 'Ad'
        tval=true
        fval=false

}

property.cfm

<cfscript>
// Instantiate the component
componentPath = "myProps";
componentInstance = createObject("component", componentPath);
// Get metadata for the component
metadata = getComponentMetaData(componentPath);
// Loop through all functions (methods) to find getters
results = {};
for (method in metadata.functions) {
// Check if the method starts with "get" or "is" (for booleans)
if (left(method.name, 3) == "get" || left(method.name, 2) == "is") {
try {
// Dynamically call the getter method
propertyName = method.name; // getPropertyName or isPropertyName
results[propertyName] = componentInstance[propertyName]();
} catch (any e) {
results[propertyName] = "Error retrieving value: " & e.message;
}
}
}
// Dump the result of all getter method calls
writeDump(var=results, label="Getter Results");
</cfscript>
<cfscript> // Instantiate the component componentPath = "myProps"; componentInstance = createObject("component", componentPath); // Get metadata for the component metadata = getComponentMetaData(componentPath); // Loop through all functions (methods) to find getters results = {}; for (method in metadata.functions) { // Check if the method starts with "get" or "is" (for booleans) if (left(method.name, 3) == "get" || left(method.name, 2) == "is") { try { // Dynamically call the getter method propertyName = method.name; // getPropertyName or isPropertyName results[propertyName] = componentInstance[propertyName](); } catch (any e) { results[propertyName] = "Error retrieving value: " & e.message; } } } // Dump the result of all getter method calls writeDump(var=results, label="Getter Results"); </cfscript>
<cfscript>
    // Instantiate the component
    componentPath = "myProps";
    componentInstance = createObject("component", componentPath);
    
    // Get metadata for the component
    metadata = getComponentMetaData(componentPath);

    // Loop through all functions (methods) to find getters
    results = {};
    for (method in metadata.functions) {
        // Check if the method starts with "get" or "is" (for booleans)
        if (left(method.name, 3) == "get" || left(method.name, 2) == "is") {
            try {
                // Dynamically call the getter method
                propertyName = method.name; // getPropertyName or isPropertyName
                results[propertyName] = componentInstance[propertyName]();
            } catch (any e) {
                results[propertyName] = "Error retrieving value: " & e.message;
            }
        }
    }

    // Dump the result of all getter method calls
    writeDump(var=results, label="Getter Results");
</cfscript>

Get help faster and easier

New user?