Total Pageviews

Tuesday, July 26, 2011

MVC portlet in Liferay 6

The Liferay 6 plugins SDK is fully re-architectured. The ext environment comes now as plugin, and therefore adding new fields(customization) the core liferay portlets of Liferay is now a bit difficult as it was quite easy in LR5. The normal way most of us are accustomed to creating a portlet was through the StrutsPortlet class which is Liferay Struts bridge. But we cannot extend this class in the plugins SDK as the StrutsPortlet class is packaged within the portal-impl.jar file, which is not accessible in the plugins SDK.

There is a new addition - MVCPortlet, which is Liferay MVC pattern class. When we create a portlet in the Plugins SDK,  we get an MVCPortlet. You can chek it by viewing the <portlet-class> attribute of portlet.xml file. Some of its major features are - page management, automatic display of success messages, automatically calling the appropriate action methods an so on. This class extends the LiferayPortlet class.  

To do some custom task by this MVC Portlet, we need to create a new class that must extend the MVCPortlet. So, the question is whay to extend MVCPortlet class? My answer is quite small - Extending MVCPortlet class will help us various ways, broadly we can say - we'll get about all benefits of MVCPortlet class and will add our own functionality in the class we are writing. 

Try creating with me by following the steps mentioned below - 

1. Create a new portlet by entering the command (must be in portlet folder of plugin)
create abc "abc"

NOTE: I suggest you to go and examine the xml files which are created by default.

2. Now go to '\portlets\abc-portlet\docroot\WEB-INF' and open 'portlet.xml' file. Modify the <portlet-class> attribute. The default valuve will be <portlet-class>com.liferay.util.bridges.mvc.MVCPortlet</portlet-class>. Give here the package of your class. we are giving ''.

3. In the <init-param> attribute, give the relative path of the jsp that you wish to open by default, when the portlet gets loded. For, instance we are giving <value>/html/com/xyz/view.jsp</value>.

4. Now create the class in the respective package. We writing the following ABCAction class in '\portlets\abc-portlet\docroot\WEB-INF\src\com\xyz\action'

5. Now just one more thing, create the jsp files in the respective path. here, we will create in '\portlets\abc-portlet\docroot\html\com\xyz' (don't bother to create the folder and files if u need, ypu'll need here to create html folder in docroot). Now the point to coin in mind that we must have the same name of the <portlet:actionURL> corresponding to which function we wish to invoke for our custom class. We here have the name of the actionURL and  function is 'customFunction'


This is all I've did. Hope, you'll find this article helpful.

Thursday, July 21, 2011

Tabs in Portlets

Hi all,
Making tabs in Liferay portlet is quite easy. We can make it with very limited code.
I'm giving an example of tabs in a struts portlet. (I hope you can make one, and if not then please refer to my old posts for the same)

1. Write the following code in the jsp of portlet, you wish to make tabs. I'm making it in view.jsp
2. Now make three jsp files with the names 'about.jsp', 'siteMap.jsp' and 'contactUs.jsp'. These are the jsp files that get included in case of the respective tabs.

3. Make the following entry in struts-config.xml
4. finally, add following in tiles-defs.xml
This is all for making tabs in portlet. Hope this will help.