Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Derek Li
PortletLayoutListener
November 2, 2011 8:48 AM
Answer

Derek Li

Rank: New Member

Posts: 14

Join Date: April 27, 2011

Recent Posts

Hi all,

I'm trying to perform some actions while a porltet is removed from the page. According to the API doc, I know that I can get the portlet id and the plid(BTW, what is a plid?), but the work I want to do here requires to get the page id and some info from the preference of the portlet being removed. So, what APIs can I use to get those info?

Thanks a lot.
Derek Li
RE: PortletLayoutListener
November 2, 2011 11:37 AM
Answer

Derek Li

Rank: New Member

Posts: 14

Join Date: April 27, 2011

Recent Posts

Now I sort of know that I can get portlet preferences with PortletPreferencesLocalServiceUtil.getPortletPreferences(plid, portletid) , but there's no detailed doc describing the returned values. Can someone please give some info?

I did some google and find plid is the page id. But how can I get the corresponding page name with this id to get the same results just as the following code:

ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
themeDisplay.getLayout().getName(themeDisplay.getLocale());

I know I can use:

LayoutLocalServiceUtil.getLayout(plid)

to get the layout then invoke the getName() method to get the page name, but how do I get the themeDisplay.getLocale()?


Besides, where should I define this listener to make Liferay aware of it? Thanks a lot.
Amos Fong
RE: PortletLayoutListener
November 3, 2011 1:54 AM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1898

Join Date: October 7, 2008

Recent Posts

Hi Derek,

You can define your portletLayoutListener in liferay-portlet.xml. See the journal content portlet for an example:

1<portlet>
2        <portlet-name>56</portlet-name>
3        <icon>/html/icons/journal_content.png</icon>
4...
5        <portlet-layout-listener-class>com.liferay.portlet.journalcontent.JournalContentPortletLayoutListener</portlet-layout-listener-class>


At this point it is impossible to find themeDisplay.getLocale() because it's the locale of the current user but you can get the default one with LocaleUtil.getDefault().
Derek Li
RE: PortletLayoutListener
November 3, 2011 8:55 AM
Answer

Derek Li

Rank: New Member

Posts: 14

Join Date: April 27, 2011

Recent Posts

Amos Fong:
Hi Derek,

You can define your portletLayoutListener in liferay-portlet.xml. See the journal content portlet for an example:

1<portlet>
2        <portlet-name>56</portlet-name>
3        <icon>/html/icons/journal_content.png</icon>
4...
5        <portlet-layout-listener-class>com.liferay.portlet.journalcontent.JournalContentPortletLayoutListener</portlet-layout-listener-class>


At this point it is impossible to find themeDisplay.getLocale() because it's the locale of the current user but you can get the default one with LocaleUtil.getDefault().



Thanks a lot, Amos. Here comes the last question:

I found that the preferences data saved in DB was in XML format, is there a simple way to transform into com.liferay.portlet.Preference?
Amos Fong
RE: PortletLayoutListener
November 3, 2011 7:04 PM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1898

Join Date: October 7, 2008

Recent Posts

The code used in JournalContentPortletLayoutListener.java should also work for you:

1        Layout layout = LayoutLocalServiceUtil.getLayout(plid);
2
3        PortletPreferences preferences =
4            PortletPreferencesFactoryUtil.getPortletSetup(
5                layout, portletId, StringPool.BLANK);
6
7        String articleId = preferences.getValue("article-id", null);