I would like to get both values, and since init(Portletconfig) is executed when loading the portlet, I don’t see any doubt about whether this values should be available.
For portletId I tried
String portletId = ((PortletConfigImpl) portletConfig).getPortletId();
but it seems I can’t. Guess it is because the impl is in another jar not meant to be accessed from portlets
By the way, my main goal is to get to pass both params to another non-request context so I can do
final PortletPreferences prefs = PortletPreferencesFactoryUtil.getLayoutPortletSetup(LayoutLocalServiceUtil.getLayout(plid), portletId);
to read portlet’s prefs in real time. If there is any other way to indicate that from init(), like getting the whole preferences it would be enough
EDIT: I found a different approach, and opened a new question with slightly changes
Liferay: get PortletID and companyID from init()
So… If I understand it right, your goal is to read out portlet preferences inside the init method of your Portlet class.
According to the API, the
PortletPreferencesobject can be retrieved from aPortletRequestinstance, which is available in bothdoView()andprocessAction()classes. E.g.:It is important to note that in Liferay, portlet preferences by default only exist within the scope of a page, or, in Liferay terms, a
Layout, which is identified by aplid, short-hand for page layout id.Concerning your
init()method, the portlet API dictates that this method should be called “before the first portlet request is handled”. In Liferay, a new instance (and only ONE instance) of your portlet class is created at deploy time, not when you add a portlet on a page. After instantiation, the portal container will call theinit()method of the portlet class.Conclusion: it doesn’t make sense at all to retrieve portlet preferences in the
init()method of your portlet class, because at that point the portlet doesn’t have any context (read:Layout) from which it should retrieve the preferences.