This website uses cookies to ensure you get the best experience on our website.

Skip to content
LOGO
  • Company

    About IGNEK

    Learn about our story and our mission.

    Careers

    We're hiring!

    We always looking for talented peoples. Join our team!

    Blogs

    The latest industry news, updates and info.

    Case Studies

    Take a closer look at the projects we've delivered

    Webinar

    Watch our latest organized webinar

    Get in touch with our HR team

    • hr@ignek.com
    • +91 93284 95160
    • Ahmedabad, Gujarat, India – 382470
  • Services

    Enterprise Portal Development

    Custom Enterprise Portal Development for flawless Solutions

    Dedicated Development Team

    Expand Teams, Optimize Development with Our Expertise

    Back-end Development

    Empowering your digital presence with robust backend development expertise

    Front-end Development

    Crafting engaging user experiences through expert frontend development

    Digital Transformation

    Embrace digital transformation by modernizing process

    SaaS Development

    Transform your business with SaaS Innovative Solutions

    Technologies

    Liferay Services

    Development & Customization

    Theme

    Upgradation

    Migration

    Proof of Concept

    Performance Tunning

    Architecture

    Support & Maintenance

    E-commerce

    Expert Advice

    React Services

    Enterprise Development

    Custom Application

    Single Page Application

    Architecture

    API Integration

    Migration

    Consulting

    Maintenance & Support

    Spring Boot Services

    Web Service

    MVC Web Development

    API Integration

    Security

    Migration

    Microservices

    Support & Maintenance

    AEM Services

    Consulting Service

    Site Development

    Migration & Upgradation

    Integration

    Maintenance & Support

    Custom Solutions

    Content Management

    Team Augementation

  • Solution

    Ready for digital excellence

    In our rapidly evolving world, businesses are always on the lookout for fresh ways to improve their operations and connect with their audiences.

    Contact US

    Solutions

    SaaS : Software As A Service

    Transforming industries through cutting edge SaaS solutions.

    Customer Portal : Boost Business Productivity

    Streamline operations and enhance productivity with our Customer Portal solution.

    Liferay Based Intranet Portal

    Internal portal for company communication, collaboration and resources

    Integration

    Matomo Integration with Liferay

    Integrate Matomo to enable user interactions seamlessly.

    Microsoft Teams integration with Liferay

    Integrate to enable seamless collaboration, messaging within your portal.

    Jira Integration With Liferay

    Optimizes business operations by integrating with Jira.

  • Hire Us

    Liferay

    Get expert Liferay developers for seamless portal solutions.

    React JS

    Get expert ReactJS developers for dynamic web solutions.

    Web Developer

    Get custom web solutions from IGNEK's expert developers.

    Spring Boot

    Get top-notch Spring Boot developers for your project success!

    Healthcare

    Get top Healthcare Developers for cutting-edge medical software.

    MERN Stack

    Get expert MERN developers from IGNEK for custom, innovative project solutions.

    Why Hire Developers From IGNEK ?

    • Certified Developer
    • Transparent Communication
    • Flexible Hiring Modals
    • Fully Signed NDA
    • Cost Effective
    • Easy Exit Policy

    Get in touch with our Sales team

    • sales@ignek.com
    • +91 6351576580
    • info@ignek.com
    • Ahmedabad, Gujarat, India – 382470
SCHEDULE CALL
  • COMPANY
    • About
    • Case Studies
    • Blogs
    • Career
    • Webinar
  • SERVICES
    • Enterprise Portal Development
    • Dedicated Development Team
    • Back-end Development
    • Front-end Development
    • Digital Transformation
    • SaaS Development
  • SOLUTION
    • Customer Portal:  Boost Business Productivity
    • SaaS : Software as a Service
    • Liferay Based Employee Intranet Portal
  • TECHNOLOGY
    • Liferay Services
      • Liferay Development and Customization
      • Liferay Theme Development Service
      • Liferay DXP 7.4 Upgrade
      • Liferay Migration
      • Liferay Proof Of Concept
      • Liferay Performance Tuning
      • Liferay Architecture Design Service
      • Liferay Support And Maintenance Service
      • Liferay Ecommerce Development
      • Liferay Expert Advice
    • ReactJS Services
      • ReactJS Enterprise Application Development
      • ReactJS Custom Application Development
      • ReactJS Single Page Application Development (SPA)
      • ReactJS Applications Architecture
      • ReactJS API Integration
      • ReactJS Migration
      • ReactJS Consulting
      • ReactJS Maintenance and Support
    • Spring Boot Services
      • Spring Boot Web Development Service
      • Spring MVC Web Development
      • Spring Boot API Integration Service
      • Spring Boot Security
      • Spring Boot Migration Service
      • Spring Boot Microservices
      • Spring Boot Support & Maintenance Service
    • AEM Development Services
      • AEM Consulting Services
      • AEM Site Development
      • AEM Migration & Upgradation
      • AEM Integration Services
      • AEM Maintenance & Support
      • AEM Content Management
      • Custom AEM Solutions
      • AEM Team Augmentation
  • INTEGRATION
  • HIRE US
    • Hire Liferay Developer
    • Hire ReactJS Developer
    • Hire Spring Boot Developer
    • Hire Healthcare Developer
    • Hire Web Developer
    • Hire MERN Stack Developer
  • CONTACT US
  • Company

    About IGNEK

    Careers

    We're hiring!

    Blogs

    Case Studies

    Webinar

    Get in touch with our HR team

    • hr@ignek.com
    • +91 93284 95160
    • Ahmedabad, Gujarat, India – 382470
  • Services

    Enterprise Portal Development

    Dedicated Development Team

    Back-end Development

    Front-end Development

    Digital Transformation

    SaaS Development

    Technologies

    Liferay Liferay Services
    • Development & Customization
    • Theme
    • Upgradation
    • Migration
    • Proof of Concept
    • Performance Tuning
    • Architecture
    • Support & Maintenance
    • E-commerce
    • Expert Advice
    React React Services
    • Enterprise Development
    • Custom Application
    • Single Page Application
    • Architecture
    • API Integration
    • Migration
    • Consulting
    • Maintenance & Support
    Spring Boot Spring Boot Services
    • Web Service
    • MVC Web Development
    • API Integration
    • Security
    • Migration
    • Microservices
    • Support & Maintenance
    AEM AEM Services
    • Consulting Service
    • Site Development
    • Migration & Upgradation
    • Integration
    • Maintenance & Support
    • Custom Solutions
    • Content Management
    • Team Augmentation
  • Solution

    Ready for digital excellence

    In our rapidly evolving world, businesses are always on the lookout for fresh ways to improve their operations and connect with their audiences.

    Contact US

    Solutions

    SaaS : Software As A Service

    Customer Portal : Boost Business Productivity

    Liferay Based Intranet Portal

    Integration

    Matomo Integration with Liferay

    Microsoft Teams integration with Liferay

    Jira Integration With Liferay

  • Hire Us

    Liferay

    React JS

    Web Developer

    Spring Boot

    Healthcare

    MERN Stack

    Why Hire Developers From IGNEK ?

    • Certified Developer
    • Transparent Communication
    • Flexible Hiring Modals
    • Fully Signed NDA
    • Cost Effective
    • Easy Exit Policy

    Get in touch with our Sales team

    • sales@ignek.com
    • +91 6351576580
    • IGNEK
    • Ahmedabad, Gujarat, India – 382470
  • SCHEDULE CALL

CRUD Operations in Liferay Portlet with custom entity

  • Liferay
  • October 22, 2019

Share On :

Introduction:

Service Builder is a code generation tool built by Liferay that allows developer to create custom entities. Service Builder generates necessary model, persistence and service layers based on service.xml. These layers provide a clean separation of concerns and allowing you to focus on the higher level aspects of the service design. All of Liferay’s services either local or remote services are generated by Service Builder.

Prerequisites:
  • Java
  • Liferay portal 7/7.x
Environment Requirement:
  • JDK 8
  • Eclipse
  • MySQL
  • Liferay Portal
  • Blade CLI (read more)
  • Gradle (read more)

Assuming that you have already created a Liferay-workspace project in eclipse IDE.

Here we will create custom entity called “Student” and perform Create, Read, Update and Delete operation on this custom entity.

Follow below steps to complete CRUD operation for your custom entity:

1. Create service-builder module for your custom entity

  1. Go to liferay workspace project → modules → new
  2. Select other → Liferay → Liferay Module Project and Click on “Next”
  3. Enter project name
  4. Select “Project Template Name” as “service-builder” and Click on “Next”
  5. Enter Package name and click on “Finish”. The necessary file structure for service-builder automatically get created as below.
Service builder module creation in Liferay

2. Add student entity in xxx-service/service.xml like as below

				
					// service.xml //
<?xml version="1.0"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 7.2.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_7_2_0.dtd">

<service-builder dependency-injector="ds" package-path="com.ignek.student">
	<namespace>stud</namespace>
	<entity local-service="true" name="Student" remote-service="true">

		
		<column name="studentId" primary="true" type="long"></column>

		
		<column name="groupId" type="long"></column>

		
		<column name="companyId" type="long"></column>
		<column name="createdby" type="long"></column>
		<column name="modifiedby" type="String"></column>
		<column name="createDate" type="Date"></column>
		<column name="modifiedDate" type="Date"></column>

		
		<column name="enrollmentNo" type="String"></column>
		<column name="firstName" type="String"></column>
		<column name="lastName" type="String"></column>
		<column name="contactNo" type="String"></column>
		<column name="city" type="String"></column>

	</entity>
</service-builder>

				
			

3. Build the service-builder module

  1. In terminal, navigate to the root directory of your service-builder project
  2. Execute the below command to build the service-builder module

blade gw buildService

  1. The necessary file structure for service-builder automatically gets created as below. It will automatically generate model, persistence, and service layers
Automatic creation of service builder structure
  1. Execute below command to deploy the service-builder module

blade gw deploy

4. Create MVC Portlet 

  1. Go to liferay workspace project → modules → new
  2. Select other → Liferay → Liferay Module Project and Click on “Next”
  3. Enter project name
  4. Select “Project Template Name” as “mvc-portlet” and Click on “Next”
  5. Enter Package name and Click on “Finish”. The necessary file structure for mvc module will gets created as below
Create MVC Portlet in Liferay Workspace

5. In order to add dependency of student-api in mvc portlet, add below line in “build.gradle” of your mvc portlet.

				
					// build.gradle //
dependencies {
	...
	/*
	compileOnly project(":modules:{your service-builder module name}:{your module-api}")
	*/
	compileOnly project(":modules:student:student-api")
}

				
			

6. Now create add-student.jsp file in same directory as view.jsp. Add below code to add-student.jsp.

				
					
<%@ include file="init.jsp"%>
<portlet:defineObjects />
<portlet:actionURL name="addStudent" var="addStudentActionURL"/>
				
<h2>Add Student Form here !</h2>
<aui:form action="<%=addStudentActionURL %>" name="studentForm" method="POST">
	<aui:input name="enrollmentNo" >
 		<aui:validator name="required"/>
 		<aui:validator name="alphanum"/>
	</aui:input>
	<aui:input name="firstName" >
 		<aui:validator name="required"/>
 		<aui:validator name="alpha"/>
	</aui:input>
	<aui:input name="lastName" >
 		<aui:validator name="required"/>
 		<aui:validator name="alpha"/>
	</aui:input> 
	<aui:input name="contactNo" >
 		<aui:validator name="required"/>
 		<aui:validator name="string"/>
	</aui:input>
	<aui:input name="city">
 		<aui:validator name="required"/>
 		<aui:validator name="alpha"/>
	</aui:input>  

	<aui:button type="submit" name="" value="Submit"></aui:button>
</aui:form>

				
			
Output of add-student.jsp
Student addition form page

7. Now implement the process action method to add student in database

				
					// StudentCrudPortlet.java //
package com.ignek.student.portlet;

@Component(
          ...  
)
public class StudentCrudPortlet extends MVCPortlet {
	private Log log = LogFactoryUtil.getLog(this.getClass().getName());
	
	@Reference
	CounterLocalService counterLocalService;
	@Reference
	StudentLocalService studentLocalService;

	@ProcessAction(name = "addStudent")
	public void addStudent(ActionRequest actionRequest,ActionResponse actionResponse) {
		long studentId = counterLocalService.increment(Student.class.getName());
		String enrollmentNo = ParamUtil.getString(actionRequest, "enrollmentNo");
		String firstName = ParamUtil.getString(actionRequest, "firstName");
		String lastName = ParamUtil.getString(actionRequest, "lastName");
		String contactNo = ParamUtil.getString(actionRequest, "contactNo");
		String city = ParamUtil.getString(actionRequest, "city");
	
		Student student = studentLocalService.createStudent(studentId);
		student.setStudentId(studentId);
		student.setEnrollmentNo(enrollmentNo);
		student.setFirstName(firstName);
		student.setLastName(lastName);
		student.setContactNo(contactNo);
		student.setCity(city);
		
		studentLocalService.addStudent(student);
	}
}

				
			

8. Now override render method of portlet to fetch all students and send students list to view.jsp

				
					// StudentCrudPortlet.java //
package com.ignek.student.portlet;

@Component(
    ...
)
public class StudentCrudPortlet extends MVCPortlet {

	@Reference
	StudentLocalService studentLocalService;

	@Override
	public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException{
		List<Student> studentList = studentLocalService.getStudents(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
		renderRequest.setAttribute("studentList", studentList);		
		super.render(renderRequest, renderResponse);
	}
}

				
			

9. Now add below code in view.jsp

				
					// view.jsp //
<%@ include file="init.jsp"%>
<portlet:defineObjects />
 
<%  List<Student> studentList = (List<Student>)request.getAttribute("studentList"); %>
<portlet:renderURL var="addStudentRenderURL">
    <portlet:param name="mvcPath" value="/add-student.jsp"/>
</portlet:renderURL>
 
<div class="mb-5">
    <a href="<%= addStudentRenderURL %>" class="btn  btn-primary btn-default">
        <i class="glyphicon glyphicon-plus"></i> Add Student
    </a>
</div>
<table class="table table-striped">
    <tr >
        <th>Enrollment No</th>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Contact No</th>
        <th>City</th>
        <th colspan="2" style="width: 100px">Action</th>
    </tr>
    <c:forEach items="${studentList}" var="student">  
    
        <portlet:renderURL var="updateStudentRenderURL">
            <portlet:param name="mvcPath" value="/update-student.jsp"/>
            <portlet:param name="enrollmentNo" value="${student.enrollmentNo}"/>
            <portlet:param name="firstName" value="${student.firstName}"/>
            <portlet:param name="lastName" value="${student.lastName}"/>
            <portlet:param name="contactNo" value="${student.contactNo}"/>
            <portlet:param name="city" value="${student.city}"/>
            <portlet:param name="studentId" value="${student.studentId}"/>
        </portlet:renderURL>
        
        <portlet:actionURL name="deleteStudent" var="deleteStudentActionURL">
            <portlet:param name="studentId" value="${student.getStudentId()}"/>
        </portlet:actionURL>
                
        <tr> 
            <td>${student.getEnrollmentNo()}</td>
            <td>${student.getFirstName()}</td>
            <td>${student.getLastName()}</td>
            <td>${student.getContactNo()}</td>
            <td>${student.getCity()}</td>
            <td class="text-center" style="width: 50px">
                <a href="<%=updateStudentRenderURL%>" class="btn  btn-primary btn-default btn-sm px-2 py-1" >
                <i class ="glyphicon glyphicon-edit"></i>
                </a>
            </td> 
            <td class="text-center" style="width:50px">
                <a href="<%=deleteStudentActionURL%>" 
                    class="btn  btn-primary btn-default btn-sm px-2 py-1"
                    onclick="return confirm('Are you sure you want to delete this item?');"> 
                    <i class ="glyphicon glyphicon-remove"></i>
                </a>
            </td>                                     
         </tr>
    </c:forEach>
</table>

				
			
Output of view.jsp
Student details list page

10. Now create update-student.jsp file in same directory as view.jsp. Add below code to update-student.jsp

				
					// update-student.jsp //
<%@ include file="init.jsp"%>
<portlet:defineObjects/>
<portlet:actionURL name="updateStudent" var="updateStudentActionURL"/>
<aui:form action="<%=updateStudentActionURL%>" name="studentForm" method="POST"/>

<%
	String studentId = renderRequest.getParameter("studentId");
	String enrollmentNo = renderRequest.getParameter("enrollmentNo");
	String firstName = renderRequest.getParameter("firstName");
	String lastName = renderRequest.getParameter("lastName");
	String contactNo = renderRequest.getParameter("contactNo");
	String city = renderRequest.getParameter("city");
%>
<aui:form action="<%= updateStudentActionURL %>" method="post" >
	<aui:input name="studentId" type="hidden" value="<%=Long.parseLong(studentId)%>"/>
	<aui:input name="enrollmentNo" type="text" value="${student.enrollmentNo}"/>
	<aui:input name="firstName" type="text" value="${student.firstName}"/>
	<aui:input name="lastName" type="text" value="${student.lastName}" />
	<aui:input name="contactNo" type="text" value="${student.contactNo}" />
	<aui:input name="city" type="text" value="${student.city}"/> 
	<aui:input type="submit" value="Update" name="update"></aui:input>
</aui:form>

				
			
Output of update-student.jsp
Student details update Page

11. Now implement the process action methods for update and delete actions

				
					// StudentCrudPortlet.java //
package com.ignek.student.portlet;
 
@Component(
    ...
)
public class StudentCrudPortlet extends MVCPortlet {
    private Log log = LogFactoryUtil.getLog(StudentCrudPortlet.class);
 
    @Reference
    StudentLocalService studentLocalService;
 
	@ProcessAction(name = "addStudent")
    public void addStudent(ActionRequest actionRequest,ActionResponse actionResponse) {
            ...
	}
	@ProcessAction(name = "updateStudent")
    public void updateStudent(ActionRequest actionRequest,  ActionResponse actionResponse) {
        long studentId = ParamUtil.getLong(actionRequest,"studentId", GetterUtil.DEFAULT_LONG);
        String enrollmentNo = ParamUtil.getString(actionRequest, "enrollmentNo", GetterUtil.DEFAULT_STRING);
        String firstName = ParamUtil.getString(actionRequest, "firstName", GetterUtil.DEFAULT_STRING);
        String lastName = ParamUtil.getString(actionRequest, "lastName", GetterUtil.DEFAULT_STRING);
        String contactNo = ParamUtil.getString(actionRequest, "contactNo", GetterUtil.DEFAULT_STRING);
        String city = ParamUtil.getString(actionRequest, "city", GetterUtil.DEFAULT_STRING);
        
        Student student = null;
        try {
            student = studentLocalService.getStudent(studentId);
        } catch (Exception e) {
            log.error(e.getCause(), e);
        }
 
        if(Validator.isNotNull(student)) {
            student.setEnrollmentNo(enrollmentNo);
            student.setFirstName(firstName);
            student.setLastName(lastName);
            student.setContactNo(contactNo);
            student.setCity(city);
            studentLocalService.updateStudent(student);
        }
    }
 	@ProcessAction(name = "deleteStudent")
    public void deleteStudent(ActionRequest actionRequest, ActionResponse actionResponse){
        long studentId = ParamUtil.getLong(actionRequest, "studentId", GetterUtil.DEFAULT_LONG);
        try {
            studentLocalService.deleteStudent(studentId);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}

				
			
Output of delete action
Student details delete alert

Explore Our Services

Discover how we can help your business thrive, whether you’re running a small startup, an SME, or a large enterprise. We’re here to understand your unique needs and goals, offering the expertise and resources to support your journey to success.
Stay informed about our services and updates by subscribing to our newsletter—just fill in the details below to subscribe.

Loading
Loading...

Related Blogs

May 27, 2019
Liferay with React Cover Image
Liferay React Portlet
December 11, 2019
Use CAPTCHA or reCAPTCHA with custom portlet in Liferay Cover Image
Use CAPTCHA or reCAPTCHA with custom portlet in Liferay
June 23, 2020
Add custom portlet into control panel in Liferay 7.2 Cover Image
Add custom portlet into control panel in Liferay 7.2
Loading...

Digital Solutions for Your Business with IGNEK

4.9

5.0

5.0

5.0

LOGO

Making the world a better place through constructing elegant hierarchies

COMPANY

  • About
  • Career
  • Case Study
  • Blogs

SERVICES

  • Enterprise Portal Development
  • Dedicated Development Team
  • Back-end Development
  • Front-end Development
  • Digital Transformation
  • SaaS Development

HIRE US

  • Liferay
  • Spring Boot
  • ReactJS
  • Healthcare
  • MERN Stack
  • AEM

CONTACT

  • info@ignek.com
  • info@ignek.com
SALES
  • sales@ignek.com
  • (+91) 635 157 6580
CAREER
  • hr@ignek.com
  • (+91) 932 849 5160
  • E 910-912, Ganesh Glory 11, Jagatpur Road, SG Highway, Ahmedabad, Gujarat - 382470

© 2018-2025 IGNEK, Inc. All rights reserved

Linkedin Facebook X-twitter Instagram