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:-

view.jsp

Explanation:-
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:-

Demo.java


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:-

http://localhost:8080/web/guest/welcome?p_auth=VTrkoIh1&p_p_id=demo_WAR_instanciablevsnoninstanciableportlet&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&_demo_WAR_instanciablevsnoninstanciableportlet_javax.portlet.action=test

p_p_id=demo_WAR_instanciablevsnoninstanciableportlet

Here p_p_id is portletId.





Step 5:-Change to instanciable
Open liferay-portlet.xml and after icon tag provide
<instanceable>true</instanceable> 

liferay-portlet.xml

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



Conclusion

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!