Thursday, October 6, 2016

Instanceable vs Non- Instanceable portlet in Liferay

Today we will discuss the difference between Instanceable vs Non- Instanceable portlet in Liferay. 

Instanceable :- If Portlet is instanceable then we can add the portlet more than once on same page.

Non-Instanceable :-  If Portlet is non-instanceable then we can add the portlet only once on a page.

So lets discuss this in detail step by step:-

Step 1:-Create Liferay Project and Portlet 
Create a Liferay plugin project and than create a portlet in it. You can check snapshot in my previous blog Developing a MVCPortlet with Multiple Actions in Liferay.

Step 2:-Change view.jsp
Open view.jsp and paste this content:-


Here we simply create a actionURL that is handle by test method in Controller.

Step 3:-Change the Controller
Open your java class and paste this:-

Step 4:-Check the Output for  Non- Instanceable
Deploy the portlet and add this to a page and click on Gear icon and then click on Look and Feel:-

Go to Advanced Styling here you find the portletId.

Portlet ID: #portlet_demo_WAR_instanciablevsnoninstanciableportlet

demo:- This is portlet name mention in portlet.xml
instanciablevsnoninstanciable :- This is Project name 

You can also get the portletId by providing some value in name field and click submit:-

Now check the URL:-



Here p_p_id is portletId.

Step 5:-Change to instanciable
Open liferay-portlet.xml and after icon tag provide


Now again deploy the portlet and add the portlet multiple times on page.

Step 5:-Check the Output for Instanceable
Now Go to Gear icon of First portlet and check the portletId.

Portlet ID: #portlet_demo_WAR_instanciablevsnoninstanciableportlet_INSTANCE_reuQSbwUdUnE

Now Go to Gear icon of Second portlet and check the portletId.

Portlet ID: #portlet_demo_WAR_instanciablevsnoninstanciableportlet_INSTANCE_RR0shoUOEuvI

Here you can see INSTANCE id also which is different for both the instances.

Instance Id(First Portlet)  = reuQSbwUdUnE
Instance Id(Second Portlet)  = RR0shoUOEuvI


So if a portlet is non-instanciable than this can be added only once and not contain any instanceId but if portlet is instanceable than we can add this multiple time but each instance contain different Instance Id .

Project Structure:-

Hope this will Help....

Related Post:-

No comments:

Post a Comment

Total Pageviews

Number Of Unique Visitor

Free counters!