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 (like a constructor). Components are saved in a file with a .cfc extension.

 <cfcomponent>

 component displayname="myComponent" output="false" { }

cfcomponent Attribute Reference

extends

Name of parent component from which to inherit methods and properties.

output

Specifies whether constructor code in the component can generate HTML output; does not affect output in the body
of cffunction tags in the component.

displayname

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.

hint

Text to be displayed when using introspection to show information about the CFC. The hint attribute value
appears below the component name heading. This attribute
can be useful for describing the purpose of the parameter.
If the style attribute is set to document, the hint
attribute is used as the document element of the service
in the WSDL.

style
Default: rpc

CF 7+ Specifies whether a CFC used for web services uses RPC-encoded style or document-literal style:
- rpc: RPC-encoded style, default
- document: Document-literal style
If you specify document, you must also specify the namespace,
serviceportname, porttypename, and bindingname attributes. Values:
  • rpc
  • document

namespace

CF 7+ 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, ColdFusion MX
derives the namespace from the CFC class name.
This attribute applies only when style="document".

serviceportname

CF 7+ Specifies the name of the port element in the WSDL. This attribute applies only when style="document".

porttypename

CF 7+ Specifies the name of the porttype element in the WSDL. This attribute applies only when style="document".

bindingname

CF 7+ Specifies the name of the binding element in the WSDL. This attribute applies only when style="document".

wsdlfile

CF 7+ A properly formatted WSDL file to be used instead of WSDL generated by ColdFusion MX.
This attribute applies only when style="document".

implements

CF 8+ Name of the ColdFusion interface or interfaces that this component implements. If the
component implements an interface, it must
define all the functions in the interface, and the
function definitions must conform to the
definitions specified in the interface. For more
information, see cfinterface.
A component can implement any number of
interfaces. To specify multiple interface, use a
comma delimited list, of the format
interface1,interface2.

serviceaddress

CF 8+ Specifies the SOAP URL of the web service.

initmethod

CF 9+ Method that will be called when ColdFusion instantiates the component

persistent

CF 9+ Specifies CFC is persistent or not

entityname

CF 9+ Specifies the name of the entity. Entity name is the name used by the ORM related functions to work with the persistent CFC. If entityname is not specified, then the CFC name is taken as the entityname. The entityname must be unique in the application.

table

CF 9+ Specifies the name of the database table to which the CFC maps.

schema

CF 9+ Used to specify the schema name.

catalog

CF 9+ Used to specify the database catalog name.

dynamicinsert
Default: NO

CF 9+ Specifies whether INSERT SQL is to be generated at runtime.
Only those columns whose values are not null are included in the SQL.

dynamicupdate
Default: NO

CF 9+ Specifies whether UPDATE SQL is to be generated at runtime.
Only those columns whose values are not null are included in the SQL.

readonly

CF 9+ Specify whether table is readonly or not

selectbeforeupdate

CF 9+ Specify whether Hibernate should never perform an SQL UPDATE unless it is certain that an object is actually modified.
In cases when a transient object is associated with a new session using update(), Hibernate performs an extra SQL SELECT to determine if an UPDATE is actually required.

batchsize

CF 9+ An integer value that specifies the number of records to be retrieved at a single instance.

optimisticlock
Default: version

CF 9+ Determines the locking strategy.
It can be any one of the following four values:
none
version
dirty
all Values:
  • none
  • dirty
  • all
  • version

lazy
Default: YES

CF 9+ Whether loading is to be done lazily or not.

rowid

CF 9+ Row id

discriminatorColumn

CF 9+ Use this attribute to define the discriminator column to be used in inheritance mapping

discriminatorValue

CF 9+ Use this attribute to define the discriminator value to be used in inheritance mapping

joinColumn

CF 9+ Use this attribute to define the join column for inheritance mapping.

embedded

CF 9+ Marks CFC as embeded, used when a CFC has an embedded object which also needs to be persisted along with the parent's data

cacheUse

CF 9+ Use this value to specify the caching strategy to be used for caching this component's data in the secondary cache Values:
  • read-only
  • nonstrict-read-write
  • read-write
  • transactional

cacheName

CF 9+ Use this value to specify the name of the secondary cache.

saveMapping
Default: NO

CF 9+ Specifies whether the generated Hibernate mapping file has to be saved to disk. If you set the value to true, the Hibernate mapping XML file is saved with the filename "CFC name".hbm.xml in the same directory as the CFC.

accessors

CF 9+ If set to false, ColdFusion ORM does not generate the implicit getters and setters.

serializable

CF 9+ Specifies whether this component can be serialized. If you set this value to false, the component and the data in the component‚ This and Variables scopes cannot be serialized, so they are not retained on session replication, and the component is in its default state.

attribute
Default: YES

CF 9+ If the attribute is set to false at the component level, then the implicit getters and setters for the individual properties are ignored.

mappedSuperClass
Default: false

CF 9.0.1+ When true on a non persistant CFC, CFCs that extend this component can inherit properties.

Compatibility

ColdFusion:

Version 6+ CFCs Introduced including support for SOAP web services.
CF 9+ Hibernate ORM support and script based CFCs.
CF 10+ REST Services

Links more information about cfcomponent

Examples sample code using the cfcomponent tag


Script Syntax

CF 9+

component displayname="Script Widget" output="false" { 
 // functions and properties here 
}

Tag Syntax

<cfcomponent displayname="Tag Widget" output="false"> 
    <!--- functions and other values here ---> 
</cfcomponent>

Fork me on GitHub