Today we will see how to write service wrapper in Liferay 6.2. We override User service getUserCount().Here we create a class that extend the particular wrapper class and just provide the entries of our custom class in liferay-hook.xml so that liferay use our services instead of Original.
Step 1:-Create a liferay Plug project
Right Click in Project Explorer and Click New -> Liferay plugin project. Now give the Project name and select hook in plugin type:-
Step 3:-Override the getUserCount()
Step 4:-Deploy the Hook
Deploy the hook and call getUsersCount() from your portlet .
Right Click in Project Explorer and Click New -> Liferay plugin project. Now give the Project name and select hook in plugin type:-
Step 2:-Create a hook in the project
Right Click on Project ->New->Liferay Hook Configuration->Select Services
Click Next--->Click Add-->Select Service Type(UserLocalService)
For Impl Class
Click New-->Give Package Name and your Impl Class Name
Then Click Finish
This step automatically Create the entry in liferay-hook.xml.
<hook>
<service>
<service-type>com.liferay.portal.service.UserLocalService</service-type>
<service-impl>com.ipg.MyUserLocalService</service-impl>
</service>
</hook>
Step 3:-Override the getUserCount()
Open MyUserLocalService and override getUserCount()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ipg; | |
import com.liferay.portal.kernel.exception.SystemException; | |
import com.liferay.portal.service.UserLocalServiceWrapper; | |
import com.liferay.portal.service.UserLocalService; | |
public class MyUserLocalService extends UserLocalServiceWrapper { | |
public MyUserLocalService(UserLocalService userLocalService) { | |
super(userLocalService); | |
} | |
@Override | |
public int getUsersCount() throws SystemException { | |
System.out.println("This text is from getUsersCount "); | |
return super.getUsersCount(); | |
} | |
} |
Step 4:-Deploy the Hook
Deploy the hook and call getUsersCount() from your portlet .
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void doView(RenderRequest renderRequest, | |
RenderResponse renderResponse) throws IOException, PortletException { | |
try { | |
UserLocalServiceUtil.getUsersCount(); | |
} catch (SystemException e) { | |
e.printStackTrace(); | |
} | |
super.doView(renderRequest, renderResponse); | |
} |
Output:-This text is from getUsersCount
Hope this will Help....
Related Post:-
Related Post:-
No comments:
Post a Comment