Wednesday, 31 July 2013

New Action in Hook in Liferay 6.1

New Action in Hook in Liferay 6.1


In one of my projects I needed to define a new action for a Mesage Board Portlet. Overriding the action class of an existing action is cake walk. However, creating a new action and then forwarding to a custom jsp is challenging. As mentioned in the post here : http://www.liferay.com/web/mika.koivisto/blog/-/blogs/7132115 I did create a new action and it did not work owing to ClassCastException for   com.liferay.portal.struts.ActionAdapter  . I could solve this problem but then the custom jsp that was included was not wrapped in the theme. Following are the steps to get the whole thing working:
  1. Do not extend your custom action class from BaseStrutsAction instead extend from BaseStrutsPortletAction class to avoid ClassCastException
  2. Now the jsp that you will return back from the render method in your Action class will take you to jsp but without wrapping it in to theme. In order to get this working, defined the same action in struts-config-ext.xml file, specify some Action class which is already there in core portal. Specify the forward of your own, map it to a custom tiles def of your own. Then create a file called tiles-defs-ext.xml file and define the custom tiles definition. forwarding to jsp that you created in hook.
  3. Restart the tomcat server. 
  4. Deploy your hook. 
Essentially what you are doing is that you are declaring action and tiles definition in struts-config-ext and tiles-defs-ext respectively and then overriding it through a hook.

No comments:

Post a Comment