Rutvij's Odyssey

Life of a Developer and Technologies he plays with

Posts Tagged ‘portlet mode

Workaround : Making setPortletMode working in Liferay

with 3 comments

In Liferay  set portlet mode from processAction() is  not setting Portlet Mode properly.

There is a bug filed on Liferay JIRA ( http://issues.liferay.com/browse/LPS-114 ).

Its use case is  as below described in Liferay JIRA:

1. process a portlet action and set the portlets window state and portlet mode in the portlets processAction method
2. When the portlet is rendered for the first time directly after the state/mode change, then the portlet seems to be in the correct state and portlet mode. (getPortletMode / getWindowState are equal to the new settings )
3. Afterwards – when the page is rendered again – then the portlet falls back to its previous window state and portlet mode (f.e. when you make a round trip to another tab)

A patch is provided for this bug ,but still not fixed in Liferay 5.2.3. Also the patch will be useful for team working with EXT environment where they can directly apply  patch to change Liferay source code.

I found one workaround which will work without changing source code . I have tested it on Tomcat 5.5, Tomcat 6.1, Websphere 6.1 with Liferay 5.2.3 and should work for earlier versions also.

Solution Summary :

It seems Liferay is tracking mode using http parameters. We need to append those parameters in page. Need to add few Query String parameters to Portal Page which contains the portlet.

p_p_id=<PortletId>&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view

<PortletId> : It is the portlet Id for target Portlet.

Step by Step Solution:

  1. Go to Portlet Preferences.
  2. You can see default link “ Return to Full Page “ . Right click on it. It will popup browser menu copy the link address.
  3. Copy it in to text editor, for my portlet it is :
    http://localhost:8080/web/test/mychamp?p_p_id=MyChamp_WAR_MyChamp&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1
  4. We need only following part for my portlet: p_p_id=MyChamp_WAR_MyChamp&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view
    copy it,according to your portlet/war name it will be different.
  5. Go To Manage pages menu.
  6. Select the page which contains the target portlet.  In the page’s Query String  paste the filtered query String.
  7. Save changes.
  8. Come back to portlet and retest after saving preferences , even if you come from different page it will work as per expected.

Written by rutvijshah

January 10, 2010 at 1:09 pm