Adding Fields with Predefined Options
Fields with predefined options are essential for streamlining data entry, standardizing inputs, and improving data integrity. To implement these fields with objects, you must first create the picklists, which are lists of key/name pairs stored as string values. Then you can create fields in your object that source predefined options from the picklists. Clarity has several data points they can implement with picklists. These include products of interest, regions available for shipping, and types of tickets they expect to receive.
By creating picklists with relevant data for their object fields, Clarity can improve reporting, consistency, and overall data quality. Here you’ll learn about creating picklists and using them to create object fields with predefined options.
Using Picklists
Liferay picklists are predefined lists of string values that can include any number of items. You can create picklists through Liferay’s UI by navigating to Global Menu > Control Panel > Picklists. When you save an empty picklist definition, an external reference code (ERC) is automatically generated for it, and you may begin adding items to it.
Each item in a picklist consists of a name/key pair. The name determines the item’s display name, and it can be localized after creation. The key determines the standard identifier for the item that is understood by applications in the backend. Keys may contain only letters and numbers. When you save a picklist item, an ERC is generated for it. You may edit the name or ERC after creation, but not the key.
Once you have created a picklist and populated it with items, you can use it to implement object fields with predefined options.
Adding Picklist Fields
Liferay supports two types of picklist-based fields for objects:
Field Type | Description |
---|---|
Single select | Stores one value from a picklist. |
Multi-select | Stores one or more values from a picklist. |
Single select fields function as drop-down menus from which a user can choose one option from the source picklist. You can configure single select fields to use a default value, which can be static or dynamic. For example, in a ticketing system application, you can use a single select field to assign ticket priorities (e.g., Low
, Medium
, High
). Single select fields can also enable custom state flow implementations, where the picklist options are various possible states for the object. In the ticketing system example, you could implement different progress states for a ticket object (e.g., Open
, Closed
, In Progress
, etc.). You’ll learn more about state flow implementations later in the course.
Multi-select picklist fields solve use cases where you want to assign multiple values to a single object. They function as checkboxes that allow one or more selections. In the ticketing app example, you may want to assign multiple affected components or departments to a single ticket object. In Clarity’s distributor management app, applicants could select products of interest, or they could indicate the regions in which they plan to operate.
Best Practices for Picklists
Fields with predefined options are a powerful piece of your data modeling toolkit, so it’s important to be intentional about how you design and implement your picklists. Limit the number of choices in a list to keep it manageable and prevent user confusion. Excessive granularity of options can lead to inconsistent use, which makes your object less useful overall.
Always use clear, descriptive terms in picklists to improve user experience. Abbreviations and overly technical language can obscure the purpose of a field and make your application less intuitive. To that end, you should design your picklists to accommodate future additions without impacting the current options. Liferay also supports language localization for picklists, which ensures consistent data entry across regions and facilitates communication among diverse users.
Liferay recommends the following standard naming conventions for items in picklists:
Picklist Item Attribute | Naming Convention |
---|---|
Name | Picklist Item |
Key | picklistItem |
External Reference Code (ERC) | PICKLIST_ITEM |
Conclusion
Employing picklist-based fields with predefined options can make your objects more intuitive to use, which in turn improves the performance of your application. Next, you’ll learn about calculated fields.
Capabilities
Product
Education
Contact Us