2

I have created custom entity employee. Now I want to add listeners for this entity so that I can track add/edit/delete employee operations.

In Liferay for portal enitites like Blogs, Group, User etc we can add properties like

value.object.listener.com.liferay.portal.model.Group=com.smb.test.hook.listeners.GroupListener

in portal.properties via hook-plugin.

But for custom entity this approach does not seem to work.

Any help would be appreciated.

Prakash K
  • 11,669
  • 6
  • 51
  • 109
suyash
  • 1,254
  • 1
  • 15
  • 33

1 Answers1

6

For custom entity, we need to add the listener property in service-ext.properties instead of the portal.properties file.

For my employee entity I have added following property in service-ext.properties file:

value.object.listener.com.smb.employee.model.Employee=com.smb.employee.hook.listeners.EmployeeListener

Note: We need to manually create service-ext.properties file in src folder besides the service.properties file. We could have updated service.properties but since it auto-generates our changes would be lost and hence service-ext.properties is the correct liferay approach.

Here is the location of the service-ext.properties file:

where does service-ext.properties should be created

Here is my service.xml:

<service-builder package-path="com.smb.employee">
    <author>Suyash</author>
    <namespace>smb</namespace>

    <entity name="Employee" local-service="true" remote-service="true">

        <!-- PK fields -->

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

        <!-- Audit fields -->

        <column name="companyId" type="long" />
        <column name="userId" type="long" />
        <column name="userName" type="String" />
        <column name="createDate" type="Date" />
        <column name="modifiedDate" type="Date" />

        <!-- Other fields -->

        <column name="field1" type="String" />
        <column name="field2" type="boolean" />
        <column name="field3" type="int" />
        <column name="field4" type="Date" />
        <column name="field5" type="String" />

        <!-- Order -->

        <order by="asc">
            <order-column name="field1" />
        </order>

        <!-- Finder methods -->

        <finder name="Field2" return-type="Collection">
            <finder-column name="field2" />
        </finder>
    </entity>

    </entity>
</service-builder>
Prakash K
  • 11,669
  • 6
  • 51
  • 109
suyash
  • 1,254
  • 1
  • 15
  • 33