Creating Your First Liferay Portlet
Step-by-Step Guide for Beginners (Liferay 7.x)
Introduction
If you are new to Liferay DXP, the very first real development milestone is:
❓ How do I create my first Liferay Portlet?
A Portlet is the core UI building block of Liferay.
Everything you see in a Liferay portal page is rendered by one or more portlets.
In this blog, you will learn:
-
What a portlet really is
-
The tools you need
-
How to create a Hello World portlet
-
How the portlet lifecycle works
-
How to deploy and test it
-
Common beginner mistakes
What Is a Liferay Portlet?
A Portlet is a modular Java UI component that:
-
Runs inside the Liferay portal
-
Renders part of a page
-
Handles user actions
-
Talks to services and APIs
-
Is deployed as an OSGi module
Examples:
-
Approval dashboard
-
Task inbox
-
Data entry form
-
Reports view
-
Workflow UI
👉 Think of a portlet as a mini web application inside the portal.
Prerequisites
Before you start:
✔ Java 11 or 17
✔ Liferay 7.3 or 7.4
✔ Liferay Workspace (recommended)
✔ Gradle (bundled with workspace)
✔ IDE: IntelliJ / Eclipse
Step 1 – Create a Liferay Workspace
Liferay Workspace is the recommended project structure.
This creates:
Step 2 – Generate a New Portlet Module
Use Blade CLI:
This creates:
Step 3 – Understand the Portlet Class
Open the generated Java class:
What this means
-
@Component→ Registers this class as an OSGi portlet -
MVCPortlet→ Default Liferay MVC framework -
view.jsp→ UI template -
display-category→ Where it appears in UI
Step 4 – Create the UI (view.jsp)
Edit:
Step 5 – Build and Deploy the Portlet
From workspace root:
If Liferay is running, you should see:
Step 6 – Add the Portlet to a Page
-
Login to Liferay
-
Go to a page
-
Click Add → Widgets
-
Find Hello Portlet
-
Drag it onto the page
🎉 You just created your first Liferay Portlet.
Understanding the Portlet Lifecycle
A portlet goes through:
In Liferay MVC:
-
doView()→ Render UI -
processAction()→ Handle form submits -
serveResource()→ AJAX calls
Step 7 – Add an Action Method
Update your portlet class:
Update view.jsp:
How Portlets Integrate with BPM & APIs
In real projects, portlets:
-
Call Spring Boot APIs
-
Trigger BPM processes (Camunda / jBPM)
-
Display workflow tasks
-
Show business dashboards
Example:
Common Beginner Mistakes 🚨
❌ Putting heavy business logic inside the portlet
❌ Tight DB coupling
❌ Ignoring OSGi dependencies
❌ Hardcoding URLs
❌ No error handling
❌ No logging
Best Practices (Production-Proven)
✔ Keep portlets thin (UI only)
✔ Move business logic to Spring Boot
✔ Use REST APIs
✔ Externalize configs
✔ Use headless APIs
✔ Add logging & monitoring
Interview Question (Very Common)
Q: What is a Liferay Portlet?
A: A modular Java UI component deployed as an OSGi bundle inside the Liferay portal.
Final Takeaway
❗ A Liferay Portlet is not just a JSP.
❗ It is a full OSGi module with lifecycle, services, and UI.
Once you understand how to build a basic portlet, you can:
-
Build workflow dashboards
-
Create approval portals
-
Integrate BPM engines
-
Build enterprise UI
💼 Professional Support Available
If you are facing issues in real projects related to enterprise backend development or workflow automation, I provide paid consulting, production debugging, project support, and focused trainings.
Technologies covered include Java, Spring Boot, PL/SQL, Azure, CMS and workflow automation (jBPM, Camunda BPM, RHPAM).
📧 Contact: ishikhanirankari@gmail.com | info@realtechnologiesindia.com
🌐 Website: IT Trainings | Digital metal podium
Comments
Post a Comment