Liferay 7.4 Objects
A Practical, Step-by-Step Tutorial
Building an Employee Management
Application
Introduction
If you're learning Liferay 7.4
Objects, the easiest way is to build one small real-world application step by
step. Liferay Objects lets you create custom applications and data models from
the UI without writing a separate module, and Liferay automatically integrates
them with core features and Headless REST APIs.
This tutorial walks through
building a simple Employee Management application, covering objects, fields,
relationships, picklists, layouts, views, actions, custom states, and the
Headless REST API.
1. Open Objects
Department | | 1-to-many v Employee | | 1-to-many v Project |
In Liferay 7.4, navigate to:
|
Global
Menu -> Control Panel -> Objects |
Then create an Object Folder if
you want to organize your objects. The Objects application supports fields,
relationships, actions, layouts, views, validations, and custom states.
Part 1 — Create the Department Object
Go to Control Panel ->
Objects -> Add Object, then create the object with the following settings:
|
Setting |
Value |
|
Label |
Department |
|
Plural Label |
Departments |
|
Object Name |
Department |
|
Scope |
Site |
Click Save. A newly created
object is initially a draft — you can configure its fields and other features
before publishing it.
Add Fields
Go to Fields -> Add, and
create the following fields:
|
Label |
Field Name |
Type |
|
Department Name |
departmentName |
Text |
|
Description |
description |
Long Text |
|
Manager |
manager |
Text |
Example values:
●
Department Name = Engineering
●
Description = Software Engineering Department
●
Manager = John
|
Note: Every object already has system fields
such as ID, Author, Create Date, Modified Date, External Reference Code, and
Status. |
Now
click Publish. You have created your first Liferay Object.
Part 2 — Create the Employee Object
Create another object with these
settings:
|
Setting |
Value |
|
Label |
Employee |
|
Plural Label |
Employees |
|
Object Name |
Employee |
|
Scope |
Site |
Add the following fields:
|
Field |
Type |
|
First Name |
Text |
|
Last Name |
Text |
|
Email |
Text |
|
Salary |
Decimal |
|
Joining Date |
Date |
Conceptually, your object now
looks like:
|
Employee ---------------- id firstName lastName email salary joiningDate |
Publish it.
Part 3 — Create the Relationship
Now we want a one-to-many
relationship: one Department can have many Employees.
|
Department 1 -------- * Employee |
Open Department ->
Relationships -> Add, and select:
|
Setting |
Value |
|
Label |
Employees |
|
Name |
employees |
|
Type |
One to Many |
|
Object |
Employee |
|
Note: Liferay's Objects relationship system
supports One-to-Many and Many-to-Many relationships. |
The resulting model is:
|
Department | | 1 | | * Employee |
On the Employee side, Liferay
provides the corresponding relationship field.
Part 4 — Create Object Entries
After publishing the object, you
can use its application to create actual data. For example:
Department
●
Department Name: Engineering
●
Description: Software Development
●
Manager: Rahul
Employees
|
Field |
Employee 1 |
Employee 2 |
|
First Name |
Amit |
Priya |
|
Last Name |
Sharma |
Patel |
|
Email |
amit@example.com |
priya@example.com |
|
Salary |
80000 |
90000 |
|
Department |
Engineering |
Engineering |
Now your data looks like:
|
Engineering | +--- Amit Sharma | +--- Priya Patel |
Part 5 — Add a Picklist
Suppose Employee has a status
field with the values ACTIVE, INACTIVE, and ON_LEAVE.
In Liferay 7.4 versions
supporting the current Picklists feature, go to Control Panel -> Picklists
-> Add, and create:
|
Setting |
Value |
|
Name |
Employee Status |
Add items:
●
Active
●
Inactive
●
On Leave
Then return to Employee ->
Fields -> Add, and select:
|
Setting |
Value |
|
Label |
Status |
|
Field Name |
status |
|
Type |
Picklist |
|
Picklist |
Employee Status |
Picklists can be used for
single-select and multi-select fields.
|
Note: Picklist functionality has changed
across 7.4 update levels — if you're on an older 7.4 GA/U release, the exact
UI can differ. |
Part 6 — Object Layout
By default, Liferay can generate
a basic layout. You can also create your own layout via Employee -> Layouts
-> Add. For example:
|
Employee
Details -------------------------------- Personal
Information First
Name Last
Name Email -------------------------------- Employment
Information Department Salary Joining
Date Status |
Layouts control how fields and
relationships are presented when users create and view object entries.
Part 7 — Object Views
You can create a custom view for
Employees, for example:
|
Name |
Email |
Department |
Status |
|
Amit Sharma |
amit@... |
Engineering |
Active |
|
Priya Patel |
priya@... |
Engineering |
Active |
Views determine how object
entries are displayed in the object's application page.
Part 8 — Object Actions
Objects can also perform actions
automatically when something happens to an entry. For example:
|
Employee
created | v Object
Action | v Send
notification |
Or:
|
Employee
Status = Inactive | v Object
Action | v Send
notification to HR |
Object Actions can be configured
with triggers, conditions, and actions.
Part 9 — Custom States
For more advanced applications,
you can define states such as NEW, APPROVED, REJECTED, and COMPLETED.
For example, an Expense object
could have:
|
Expense v NEW v MANAGER_APPROVED v FINANCE_APPROVED v PAID |
Liferay Objects can use
picklists as custom state fields and combine them with validations, actions,
and workflows.
Part 10 — Object REST API
One of the most useful features
for developers is that Objects are integrated with Liferay's Headless APIs.
|
Your
Application | | REST API v Liferay | v Object | v Database |
After creating an Employee
object, you can work with employee entries through Liferay's REST API rather
than creating your own MVC portlet or service layer for basic CRUD.
This is particularly useful when
building modern frontends:
|
React
/ Angular / Vue | v Liferay
REST API | v Liferay
Objects |
Liferay also provides APIs for
creating and managing object definitions themselves.
Part 11 — Model Builder
For larger applications, use
Objects -> View in Model Builder. The Model Builder visually represents your
object definitions and their relationships.
For our example:
|
+--------------+ | Department
| |--------------| |
name | |
description | +------+-------+ | 1 | | * +------v-------+ | Employee
| |--------------| |
firstName | |
lastName | |
email | |
salary | +------+-------+ | | * | +------v-------+ | Project
| |--------------| |
name | |
startDate | |
status | +--------------+ |
Model Builder is especially
useful when you have multiple objects and relationships.
Recommended Learning Path
If you're a Liferay 7.4
developer, learn Objects in this order:
1. Object Definition
2. Object Fields
3. Object Entries
4. Object Relationships
5. Picklists
6. Object Layouts
7. Object Views
8. Validations
9. Object Actions
10. Custom States
11. Workflows
12. Headless REST APIs
13. Java / OSGi integration
14. React / frontend integration
Official Documentation
The best reference is Liferay's
official Objects documentation for Liferay 7.4+.
Capstone Project
For hands-on practice, build a
complete Employee Management System covering the full workflow:
|
Department v Employee v Leave
Request v Manager
Approval v Workflow v Notification v REST
API v React
UI |
That
project will teach you almost all of the important Liferay 7.4 Object concepts
in one application.
Comments
Post a Comment