To have a settings page in your portlet in Liferay, you must implement the com.liferay.portal.kernel.portlet.ConfigurationAction
interface and configure the portlet in liferay-portlet.xml to use your class.
<portlet> <portlet-name>MyPortlet</portlet-name> <configuration-action-class>com.mydomain.myportlet.ClassThatImplementsConfigurationAction</configuration-action-class> <instanceable>false</instanceable> ... </portlet>
You should also know that inside this class you are in the Liferay configuration portlet, and not in your portlet. Thus, obtaining preferences such as
portletRequest.getPreferences();
leads to the preferences of the Liferay configuration portlet.
To get the settings of your portlet, add this method to your class
protected PortletPreferences getPortletPreferences(final PortletRequest p_portletRequest) throws Exception { String portletResource = ParamUtil.getString(p_portletRequest, "portletResource"); PortletPreferences prefs = PortletPreferencesFactoryUtil.getPortletSetup(p_portletRequest, portletResource); return prefs; }
and call it from the implemented methods
public void processAction(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception; public String render(PortletConfig portletConfig, RenderRequest renderRequest, RenderResponse renderResponse) throws Exception;
source share