NexJ Logo

Attributes and data types

A class may acquire attributes directly, or indirectly via a base class, aspect or augment. Directly defined attributes can be found in the "Attributes" tab in the class editor. Meanwhile, attributes that are acquired indirectly can be found in the "Base Attributes" tab. By default, the "Base Attributes" tab will only show 30 attributes from the immediate parent class. Developers can open the expanded search field to increase the number of attributes shown, or to narrow down attributes by name, type or other criteria.

When defining an attribute for a class, the name and type must be specified as a minimum. By convention, all attributes should have a description that describes the purpose or usage of the attribute. Ideally, any relevant use case or bug numbers should be listed too. An attribute could be of a primitive type like a boolean, or it can be an association to another class like Entity. See below for a list of available primitive types. The "Select Class..." button for an attribute type allows a developer to choose any existing class as the type.

An attribute can be calculated or persisted to a data source. In the "Value" tab, an attribute can be given an "Initializer" or "Value" expression. The initializer is commonly used to default a persisted attribute to some initial value. An attribute with a "Value" expression is otherwise known as a "calculated attribute".

A calculated attribute is usually used to store information that can be derived from one or more other attributes. Such an attribute could be marked as cached to reduce the number of times it is calculated when displayed. Other times, a calculated attribute can be used to provide a simplified facade for accessing information. For example, the entityStatus of an Entity provides a simplified view of the isClient, isProspect, and isFormerClient flags.

A transient attribute is an attribute that is neither persisted nor calculated. Such attributes are usually used as temporary placeholders in the UI, and are read during update or commit to trigger some specific logic. Another usage for this would be for passing context between events or actions. This is an uncommon scenario though, and is rarely needed.

Primitive Data Types

The following data types are available to attributes of classes. Valid values for each data types are:
any
Any type of data. This is used to store information that does not fall under a traditional type. Usually this is used to store a scheme list.

IMPORTANT: Attributes of type "any" should be made protected, as such attributes are a potential security hole when left public. If a malicious lambda expression is inserted into an attribute via RPC, then it may be unknowingly executed and cause damage. If the presentation layer needs a scheme list or lambda expression from the business model, then expose it via a public event instead.

binary
Binary data of arbitrary length.

boolean
Either true or false. Boolean values are typically the result of logical expressions. For example, the expression 5 < 10 returns the Boolean value #t, and the expression 5 > 10 returns the Boolean value #f.

currency
Numeric values that represent a monetary value. Currency data types are persisted as decimals.

date
Values that represent a calendar date. Date values cannot include a specific time value and persist at 0 hour UTC.

decimal
Numeric values that contain decimal fractions.

double
Values that represent a double-precision 64-bit floating-point number. Doubles can be used to store numbers that are too small or large to be stored in a float.

float
Values that represent a single-precision 32-bit floating-point number. They can be either whole numbers or numbers that contain a fractional component. For example, the values 2.0 and 2.1 are both floats.

integer
Whole numbers that do not include a decimal place. For example, the value 2 is an integer, while 2.0 is not.

long
Values that represent a 64-bit integer. Longs can be used to store numeric values that are too large to be stored in an integer data type.

percentage
Values that represent a percentage. Percentage data types values are persisted as doubles. In the user interface, percentage data type values are formatted as percent when a field or label is bound to the attribute.

string
Sequences of characters that represent text. String values are surrounded by double quotation marks. For example, the value "Hello World!" is a string.

Strings may contain letters, numbers, and symbols. The symbols " and \ are special characters that cannot be written directly in a string. If you want to write a double quotation mark in a string, use the token \". If you want to write a backslash in a string, use the token \\.

timestamp
Values that represent a specific date and time. Timestamp values differ from date values in that they include a time component and can be mapped to time zones other than UTC.