Portlets have an EDIT mode, and this is the way we can parametrize them.
My question is what it the best way to parametrize a portlet exactly at the moment its loaded, programmatically.
For example: I want to get Liferay to load two instances of the portlet with a certain ID, one with paramA
, second with paramB
.
To load different parameters (better known in Liferay as "Portlet Preferences") you can use PortletPreferences to store and retrieve different parameters,
PortletPreferences preferences =
PortletPreferencesFactoryUtil.getPortletSetup(
request, portletId);
The factory takes 2 parameters,
With this object you can get parameters:
String myValue = preferences.getValue("my-value");
And you can store values:
preferences.setValue("my-value", "this-value");
preferences.store();