Liferay DXP (Digital Experience Platform) provides a modular framework for developing robust web applications using Java. In this blog, we will walk through the steps required to create a custom portlet using Liferay DXP with Java, covering even the smallest configuration and setup details.
Prerequisites
- JDK 11 or later
- Liferay DXP 7.4 (or any compatible version)
- Blade CLI installed
- IDE like IntelliJ IDEA or Eclipse
Step 1: Set up Liferay Workspace
Open terminal and run the following command:
blade init liferay-workspace
Navigate to your workspace:
cd liferay-workspace
Step 2: Create a Portlet Module
blade create -t mvc-portlet -p com.example.portlet -c CustomPortlet custom-portlet
This command creates a new portlet module using the MVC Portlet template.
Step 3: Explore the Generated Files
CustomPortlet.java
- The main class for the portlet.view.jsp
- Default view template for the portlet.bnd.bnd
- Contains OSGi metadata.
Step 4: Update view.jsp
Edit src/main/resources/META-INF/resources/view.jsp
to customize the UI:
<%@ page contentType="text/html;charset=UTF-8" %>
<h1>Welcome to My Custom Portlet</h1>
<p>This is a custom portlet built with Java.</p>
Step 5: Build and Deploy the Portlet
./gradlew deploy
This will deploy your portlet to the Liferay DXP instance.
Step 6: Add the Portlet to a Page
- Login to the Liferay portal.
- Navigate to a site page or create a new one.
- Click on the "+" button to add a widget.
- Search for your portlet (e.g., "Custom Portlet").
- Drag and drop it onto the page.
Step 7: Customize Further (Optional)
You can create additional JSPs and actions, or use Spring MVC for more complex logic. You can also define PortletPreferences
, add localization files, and implement inter-portlet communication using public render parameters.
Conclusion
You've now successfully created a custom portlet with Liferay DXP using Java. From setting up the workspace to deploying the module, each step builds your foundation for more advanced Liferay development.
No comments:
Post a Comment