Data Properties
Data Properties hold the state of your component and are defined with a data structure. Each data property is assigned a default value and is automatically synchronized between server and client.
Data properties are reactive - when an action modifies a property, CBWIRE automatically re-renders only the affected parts of your template. They can hold strings, numbers, booleans, dates, arrays, and structures, and are directly accessible in templates without special syntax.
//./wires/SomeComponent.bx
class extends="cbwire.models.Component" {
data = {
"propertyName": "defaultValue"
};
}//./wires/SomeComponent.cfc
component extends="cbwire.models.Component" {
data = {
"propertyName": "defaultValue"
};
}JavaScript parses your data properties. Your data properties can only store JavaScript-friendly values: strings, numerics, arrays, structs, or booleans.
Single or double quotes must surround property names.
JavaScript is a case-sensitive language, and CFML isn't. To preserve the casing of your property names, you must surround them with quotes.
Don't do this.
data = {
propertyName: "defaultValue"
};Data properties are visible to JavaScript. You SHOULD NOT store sensitive data in them. Use locked properties for additional protection against client-side modifications.
Accessing From Actions
Using the data structure, you can access data properties from within your component actions.
Accessing From Templates
You can access data properties within your templates using #propertyName#.
Nested Properties
Organize related data using nested structures and access them with dot notation. This keeps your data organized hierarchically instead of flattening everything into top-level properties.
Accessing in Templates
Reference nested properties using dot notation in wire:model and other directives:
Accessing in Actions
Use dot notation to access and modify nested properties in your component methods:
Lifecycle Hooks
Lifecycle hooks for nested properties use underscores instead of dots. A property path like user.name.first triggers onUpdateuser_name_first():
Resetting Properties
You can reset all data properties to their original default value inside your actions using reset().
You can reset individual, some, or all data properties.
You can also reset all properties EXCEPT the properties you pass.
Locked Properties
Locked properties prevent client-side modifications to sensitive data like user IDs, roles, or permissions. Define a locked variable to protect specific properties from wire:model and other client interactions. CBWIRE throws an exception if locked properties are modified from the client.
Single Property
Multiple Properties
Template Usage
Locked properties can be displayed but not modified through form inputs:
Common Use Cases
User Management: Lock
userId,role,permissionsE-commerce: Lock product IDs, prices, inventory counts
Financial: Lock account numbers, balances, transaction IDs
Content: Lock author IDs, creation dates, publication status
Remember that locked properties are still visible in the client-side JavaScript. For truly sensitive data that shouldn't be visible to users, avoid including it in data properties altogether and access it through server-side services instead.
Last updated
Was this helpful?