google.com, pub-5747754088801811, DIRECT, f08c47fec0942fa0 Skip to main content

Liferay service finder methods

Liferay provides finder methods facility with help of service.
  • Lets say we have employee entity and we want to create the finder method base on city.
  • It allow to create finder method in it.
  • In below example we create finder method which return List of Employee.
<entity name="Employee" local-service="true" remote-service="true"
cache-enabled="false">

<column name="employeeId" type="long" primary="true" />
<column name="employeeCity" type="String" />
<column name="employeeCell" type="String" />

<finder name="EmployeeCity" return-type="Collection">
<finder-column name="employeeCity" />
</finder>


</entity>
  • Run service.
  • Our half work is done (finder method is available in persistence class).
  • EmployeeUtil in my case it is package com.sa.service.persistence inside WEB-INF.
  • There are many method available now related with findByCity for example below method which returnc collection of Employee base on city.

public static java.util.List<com.sa.model.Employee> findByEmployeeCity(
java.lang.String employeeCity)
throws com.liferay.portal.kernel.exception.SystemException {
return getPersistence().findByEmployeeCity(employeeCity);
}

  • The only class accessible outside the service builder is EmployeeLocalServiceUtil.
  • We need to make sure the finder method is also available in this class. (to access it in our portlet class)
  • This class (EmployeeLocalServiceUtil) can be used to perform CRUD operation.
  • Now copy below method in the EmployeeLocalServiceImpl.

public List<Employee> getEmployeeForEmployeeCity(String employeeCity) throws SystemException{
 

                              return this.employeePersistence.findByEmployeeCity(employeeCity);
}  
  • Run again service and now check inside EmployeeLocalServiceUtil getStudentForEmployeeCity available and you can use anywhere it.


Comments

Popular posts from this blog

Disable cache content of browser access on back button after logout liferay dxp

Some time we have requirement where we do not want to allow back button after logout and show cached browser content. Liferay provide properties which with we are able to restrict to see content on back button after logout. If user click back button after logout it will show the login page. We require to provide below properties in portal-ext.properties. Restart the server once applying below properties browser.cache.signed.in.disabled=true

Liferay crud porrtlet with Jasper Reports.

I have used Meera Prince Crud operation demo for the Jasper reports which allow to export report in PDF , word, XLS format. It will look lie below image. Find Source code for the complete example on below location. LIFERAY JASPER REPORT INTEGRATION 1 I have available PhoneManger Crud Portlet which have pagination and crud functionality. 2 I create report-listing-mobile.jrxml  file with help of Ireport tool. <?xml version="1.0" encoding="UTF-8"?> <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report-listing" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin=&q