<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
>
| Attribute | Description |
|---|---|
name
string, required
|
edit
A string; a property name. Must be a static value. |
type
string, optional
|
edit
A string; a property type name; data type. |
required
boolean, optional
|
edit
Whether the parameter is required |
default
object, optional
|
edit
This sets the default value on the property when the object is created. |
displayName
string, optional
|
edit
A value to be displayed when using introspection to show information about the CFC. The value appears in parentheses following the property name. |
hint
string, optional
|
edit
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. |
access
string, optional
|
edit
The client security context from which the method can be invoked |
getter
boolean, optional
|
edit
Specifies whether to generate getter methods or not |
setter
boolean, optional
|
edit
Specifies whether to generate setter methods or not |
Examples
editSample 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 open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)