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

Liferay portlet with alloy Ui form validator example.

 Alloy Ui  is built on YUI and we can use it in our liferay portlets.  Yui provides many component which are easy to use in our portlets  Here we see basic form validator.example with liferay portlet. Create portlet AlloyUi-portlet in eclipse. Add below content in view.jsp file Here we create two link for two JSP. <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> <script src="http://cdn.alloyui.com/2.5.0/aui/aui-min.js"></script> <link href="http://cdn.alloyui.com/2.5.0/aui-css/css/bootstrap.min.css" rel="stylesheet"></link> <portlet:defineObjects /> <portlet:renderURL var="basicform"> <portlet:param name="mvcPath" value="/BasicFormValidatorExample.jsp"/> </portlet:renderURL> <portlet:renderURL var="fullform"> <portlet:param name="mvcPath" value="/FullFormValidatorExample.jsp"/> </portlet:re...

Add custom field in user expando api liferay 6.2

Custom Field Liferay 1) The easiest way to add customfield is  add customfield with control panel. Admin -> Control panel -> Configuraton -> custom fields -> Click user -> Add custom field -> Add key and Type (e.g key - nickname type - Text field index) Click on save Now you done. Create One Hook Liferay ->  https://www.liferay.com/documentation/liferay-portal/6.2/development/-/ai/customize-and-extend-functionality-hooks-liferay-portal-6-2-dev-guide-en Override html\portlet\users_admin\user\details.jsp Add below code in jsp for the custom field nickname.     <div class="exp-ctrl-holder">            <liferay-ui:custom-attribute              className="<%= User.class.getName() %>"              classPK="<%= (selUser != null) ? selUser.getUserId() : 0 %>"               editable="<%= true %...