<cfproperty>
Defines components as complex types that are used for web services authoring.
The attributes of this tag are exposed as component metadata and are subject to inheritance rules.
Note: Lucee does not support 'lazy' attribute in cfproperty.
This tag cannot have a body.
This tag is also supported within <cfscript>
<cfproperty
name=string
type=string
required=boolean
default=object
displayName=string
hint=string
access=string
getter=boolean
setter=boolean
>
Examples
Sample syntax
<cfproperty name="UnitId" column="unit_id" unique="true" fieldtype="id" type="string" />
Serializing a CFC's properties to JSON
myCfc = new component accessors="true"{
property name="foo" type="string";
property name="bar" type="numeric";
// NOTE: nulls are skipped when serializing
property name="unset" type="numeric";
foo = "hello";
bar = 42;
};
dump(myCfc); // See CFC object with properties
jsonString = serializeJson(var=myCfc, compact=false);
writeOutput(jsonString); // Output: {"foo":"hello","bar":42}
Improve type handling and defaults with Lucee 7
myCfc = new component accessors="true" {
property name="foo" type="string";
property name="bar" type="numeric";
property name="arr" type="array" default="#[1,2,3]#";
property name="st" type="struct" default="#{lucee:"rocks"}#";
foo = "hello";
bar = 42;
};
dump(myCfc); // See CFC object with properties
jsonString = serializeJson(var=myCfc, compact=false);
writeOutput(jsonString); // Output: {"foo":"hello","bar":42}
See also
- <cfcomponent>
- Search Issue Tracker
- Search Lucee Test Cases (good for further, detailed examples)