Understanding Object Fields
Object fields represent database columns for storing different types of values. All objects include default system fields, but you can add custom fields to both draft and published objects. These fields can receive input from users, aggregate numeric values, define custom states, and more.
To implement their distributor and ticketing app, Clarity must carefully consider what kind of data they need to capture and how they intend to use it. Choosing the appropriate field type is crucial for determining how data is stored and used within your applications. Liferay objects support a variety of field types, which can be grouped into the following heuristic categories:
Field Type Category | Description |
---|---|
Text Fields | Store string-based data (names, descriptions, rich media content). |
Numeric Fields | Store numeric data (whole numbers, decimals, precise figures). |
Date and Time Fields | Store temporal data (dates, times, or both). |
Boolean Fields | Store binary data (true or false). |
Attachment Fields | Store references to uploaded files. |
Picklist Fields | Store selections from a predefined list of values. |
Calculated Fields | Calculate dynamic, read-only values based on other object data. |
Once you add a field to an object definition, you can access additional configuration options. Some of these configurations are shared by all field types, while others are unique to certain types (e.g., limiting the number of allowed characters, requiring unique values, etc.). With these options, you can ensure each data field fits your solution. Here you’ll learn more about the first five field type categories, along with best practices for using each of them.
Using Text Fields
Text fields store various types of string-based data, from plain text to rich content with formatting and media elements. They are flexible and widely used in almost every application in some capacity. Liferay objects support these types of text fields:
Field Type | Description |
---|---|
Encrypted | Store encrypted string data with an encryption key (not available in Liferay SaaS). |
Long Text | Store a text box value of up to 65,000 characters. |
Rich Text | Store text with advanced formatting tools and media elements (e.g., images, videos, audio). |
Text | Store simple text values of up to 280 characters. |
Encrypted fields are best suited for storing confidential information like passwords or personal identifiers. Organizations can use encrypted fields to protect sensitive data and satisfy security and compliance requirements. Because Clarity is using Liferay SaaS, they are not using encrypted fields in their distributor and ticketing apps.
Long Text and Rich Text fields are best suited for extended content like descriptions, comments, and notes, while the simple Text field is ideal for shorter attributes like titles and names. The flexibility of text fields means that they often require additional measures to maintain uniformity of data input. You can leverage validations to apply character limits where necessary or enforce specific formats for certain data, such as email addresses and phone numbers. Measures like these not only help users input data correctly the first time, but also help you display field data consistently across different interfaces.
Using Numeric Fields
Numeric fields store numerical values, from whole numbers to high-precision decimals. They are essential for tracking quantities and performing calculations. Liferay objects support these types of numeric fields:
Field Type | Description |
---|---|
Integer | Store an integer value up to 9 digits long. |
Long Integer | Store a large integer value up to 16 digits long. |
Decimal | Store a floating point decimal value up to 16 digits long. |
Precision Decimal | Store a high-precision decimal value with up to 16 decimal digits and no rounding. |
You can set minimum and maximum limits on any numeric field to prevent incorrect or unreasonable data entries. You can also configure certain fields to allow only unique values, which is especially useful for data like IDs or reference numbers that are used for indexing objects.
Precision Decimal fields are ideal for storing financial data because they prevent rounding errors in currency calculations. This type of numeric field is crucial for applications like invoicing and payroll systems.
Using Date and Time Fields
Date and time fields store temporal data such as dates, times, or a combination of both. Liferay objects support these types of date and time fields:
Field Type | Description |
---|---|
Date | Store date values. |
DateTime | Store date and time values. You can store time values as entered or convert them to UTC. |
Date fields are best suited for use cases where only the date is important, such as birthdates, while DateTime fields are ideal for scheduling needs, such as tracking appointments and deadlines. DateTime fields can support workflows that involve reminders or notifications. You can also automatically populate fields like createdDate
or lastModifiedDate
to track when objects were created or updated. This can improve audit trails and give you a better understanding of the lifecycle of your application data.
You should avoid using DateTime fields unless the time value is necessary, as it can otherwise complicate data input and display. If your application serves users across multiple time zones, as Clarity’s will, storing DateTime values in UTC gives you the ability to display the correct time zone to users based on their locations.
Using Boolean Fields
Boolean fields store either a true
or a false
value.
Field Type | Description |
---|---|
Boolean | Store true or false . |
Boolean fields are used to represent binary conditions such as active/inactive or yes/no. They often drive workflow behavior and are critical for capturing user decisions and preferences. You can make Boolean fields mandatory, which means they must receive a true
input. This setting is useful for cases where your application requires certain conditions to be met, like a terms of service agreement.
You can also configure Boolean fields to be true
or false
by default when you create them, which can streamline user interactions and improve quality of life. For example, a user subscription object might contain a Boolean field for opting in to a weekly newsletter. You can set this field to false
by default so that users aren’t signed up for the newsletter inadvertently or against their will.
Boolean fields are insufficient when you need to represent more than two states: true
,false
, and an indeterminate or unset condition. In these cases, a picklist field is more appropriate. You’ll learn more about picklist fields in the next lesson.
Using Attachment Fields
Attachment fields store references to uploaded files. Liferay supports any file type accepted by the Documents and Media application.
Field Type | Description |
---|---|
Attachment | Store file attachment references. By default, uploaded files can be no larger than 100 MB. |
An attachment field can only reference one uploaded file at a time. You can link attachment fields to Documents and Media for broader access, or link them to private folders, which are appropriate for confidential files. In addition, you can specify accepted file extensions and file sizes to prevent security and performance issues.
Unless they are stored in an object’s private folder, attachments aren’t automatically deleted when their corresponding entries are removed. Make sure to review and delete unused files regularly to prevent clutter. You can manage and automate attachments to objects using Liferay’s headless APIs, eliminating the overhead of uploading files manually.
Conclusion
By understanding Liferay's field types and following best practices for each, you can create well-structured objects that are scalable and suited to your specific business needs. Whether building a ticketing system or a distributor management app, choosing the right fields from the start ensures smooth operation and reliable data management. Next, you’ll learn more about picklist fields.
Capabilities
Product
Education
Contact Us