Wednesday, August 30, 2017

How to Access Custom Services in Velocity(VM) files using Service Locator?


In the previous blog we see how to to access Liferay Services in Velocity(VM) files using Service Locator. In this blog we will see how to  to access Custom Services in Velocity(VM) files using Service Locator. 

Create Service
First create services and deploy the services. Cut the jar file from lib folder and paste in ..\tomcat-7.0.42\lib\ext so that it is available to all other projects. I created a project employee-portlet which contain all the services . When i build the services employee-portlet-service.jar is created.

Note:- When you copy the jar from project lib to \tomcat-7.0.42\lib\ext make sure to delete the jar from project lib.


For Theme
If you want to access employee services in your theme you can use this code in portal_normal.vm:-


Explanation:-
Here findService() method take two arguments first is your context name(project name of your services) and second is full path of your service class.








For Web Content Templates
You can use the above code in your templates files but you need to do one extra step. Just enter :-

velocity.engine.restricted.variables=

in your portal-ext.properties and restart server.




No comments:

Post a Comment

Total Pageviews

Number Of Unique Visitor

Free counters!