22 November, 2016

Liferay MVC Portlet with Service Builder - DXP

Friends,

Here you will see how you can create Liferay MVC portlet with best practice.

If you remember, we were creating portlets in 6.X by selecting specific portlet type from IDE and choosing weather we have to use service builder or not. So there it was creating only one single portlet including service layer.

Now in DXP, you will have to separately create service layer and web portlet layer .
Now here we will have to keep 2 things in our mind.
1) Portlet specific service layer
2) Generic service layer (Which can be used across all the modules)

Identically both are same and the way of accessing the service also would be the same only difference is, if service is portlet specific then you can keep service and web layer altogether in single module project which will help for CI and build whole project.

1) Now here first step would be create new Liferay module by selecting servicebuilder as template and create.

You can also create this portlet using blade-cli tool as well.
You can use below command to create if you have install blade-cli in your local.


blade create -t servicebuilder -p com.sample -c LiferayServiceSample

2) This will create your service layer with service.xml file inside where you can define your entities and build the service. This will create
  • LiferayServiceSample-api
  • LiferayServiceSample-service

3) Now here you will not have portlet code inside and you will have to create manually again.
Create new Liferay module called LiferayServiceSample-web  where you will have to uncheck Use Default location check box and will have to create inside LiferayServiceSample project which we have created earlier.



4) If you see the created module structure, It would look like given snap


5) Now when you build root LiferayServiceSample project, it will build all below 3 modules inside and create individual jar
So as I said, this will helpful during build but it would be same if you keep your web project inside or outside of root project.

6) Here, you can find all implementation classes inside XXX-service module and all your API interfaces will be available in XXX-api module which generally being used to call services.

Checkout Sample : git clone https://bitbucket.org/liferaydxp/public.git

Popular Posts

Featured Post

Liferay 7.3 compatibility matrix

Compatibility Matrix Liferay's general policy is to test Liferay Portal CE against newer major releases of operating systems, open s...