<cfcomponent>
Creates and defines a component object; encloses functionality that you build in CFML and enclose within <cffunction> tags.
This tag contains one or more cffunction tags that define methods.
Code within the body of this tag, other than cffunction tags, is executed when the component is instantiated.
This tag must have a body.
This tag is also supported within <cfscript>
<cfcomponent
accessors=boolean
synchronized=boolean
persistent=boolean
extends=string
implements=string
modifier=none|final|abstract
displayName=string
hint=string
output=boolean
style=string
namespace=string
servicePortName=string
serviceAddress=string
portTypeName=string
bindingName=string
wsdlFile=string
alias=string
mappedSuperClass=boolean
javasettings=string
initMethod=string
><!--- body ---></cfcomponent>
| Attribute | Description |
|---|---|
accessors
boolean, optional
|
edit
If set to true, enables implicit getters and setters for the component's properties. For persistent CFCs, accessors are always enabled. |
synchronized
boolean, optional
|
edit
If set to true all calls to an instance of a component are synchronized. This setting allows a method to be executed only by one single thread at a time. |
persistent
boolean, optional
|
edit
Specifies CFC is persistent or not |
extends
string, optional
|
edit
Name of parent component from which to inherit methods and properties. |
implements
string, optional
|
edit
Lists the interfaces that the component implements, specifying the set of functions that the component must provide. |
modifier
string, optional
|
edit
Defines the type of component: |
displayName
string, optional
|
edit
A string to be displayed when using introspection to show information about the CFC. The information appears on the heading, following the component name. If the style attribute is set to document, the displayname attribute is used as the name of the service element in the WSDL. Alias: display |
hint
string, optional
|
edit
Text that displays when you use introspection to show information about the CFC. The hint attribute value appears below the component name heading. Use this attribute to describe the purpose of the component. |
output
boolean, optional
|
edit
|
bindingName
string, optional
|
edit
Specifies the name of the binding element in the WSDL. This attribute applies only when style="document". |
javasettings
string, optional
|
edit
Specifies custom When provided, these settings override any server level JavaSettings that would otherwise be applied. Since 6.2 Lucee supports specifying Maven dependencies JavaSettings in Application.cfc, Components and CFConfig.json |
Unimplemented Attribute(s)
| Attribute | Description |
|---|---|
style
string,
optional
|
edit
Specifies whether a CFC used for web services uses RPC-encoded style or document-literal style * unimplemented * |
namespace
string,
optional
|
edit
Specifies the namespace used in the WSDL when using the CFC as a document-literal style web service. If you don't specify this attribute, Lucee derives the namespace from the CFC class name. This attribute applies only when style="document". * unimplemented * |
servicePortName
string,
optional
|
edit
Specifies the name of the port element in the WSDL. This attribute applies only when style="document". * unimplemented * |
serviceAddress
string,
optional
|
edit
Specifies the SOAP URL of the web service. If you don't specify this attribute, Lucee uses the URL of the CFC in the WSDL service description. Use this attribute to specify the protocol, for example, by specifying a URL that starts with https://. This attribute applies only for web services. * unimplemented * |
portTypeName
string,
optional
|
edit
Specifies the name of the porttype element in the WSDL. This attribute applies only when style="document". * unimplemented * |
wsdlFile
string,
optional
|
edit
A properly formatted WSDL file to be used instead of WSDL generated by Lucee. This attribute applies only when style="document". * unimplemented * |
alias
string,
optional
|
edit
Defines an alternative name or alias for the component, providing flexibility in referencing the component in different contexts. * unimplemented * |
mappedSuperClass
boolean,
optional
|
edit
Indicates whether the component acts as a mapped superclass. A mapped superclass serves as a base class for other components to extend but does not itself represent a database entity. * unimplemented * |
initMethod
string,
optional
|
edit
Specifies the name of the initialization method to call when the component is instantiated using the |
Examples
editTag based syntax
<cfcomponent displayname="Hello" output="false" style="document" hint="hint for Hello">
<!--- functions and other values here -->
</cfcomponent>
Script based syntax
component displayname="Script Widget" output="false" {
// functions and properties here
}
Serializing a CFC's properties to JSON
myCfc = new component {
property name="foo" type="string";
property name="bar" 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}
See also
- Components (CFCs)
- Core CFML Language
- Static
- getClass() Method for Components
- Convert a CFML Function/Component to use in Java
- Dynamic Proxy Enhancements in Lucee 7
- RestInitApplication()
- Inline Components
- Java - Explicit Casting of a Component to a Specific Interface
- JavaSettings in Application.cfc, Components and CFConfig.json
- New Operator in Lucee
- REST Services with Lucee
- Sub Components
- <cfargument>
- <cffunction>
- <cfinterface>
- <cfinvoke>
- <cfinvokeargument>
- <cfobject>
- <cfproperty>
- <cfstatic>
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)