Reputation: 1218
I'm trying to personalize the configuration of a Liferay portlet.
configuration.jsp is:
<%@include file="/init.jsp" %>
<liferay-portlet:actionURL portletConfiguration="true" var="configurationURL" />
<%
boolean showLocationAddress_cfg = GetterUtil.getBoolean(portletPreferences.getValue("showLocationAddress", StringPool.TRUE));
%>
<aui:form action="<%= configurationURL %>" method="post" name="fm">
<aui:input name="<%= Constants.CMD %>" type="hidden" value="<%= Constants.UPDATE %>" />
<aui:input name="preferences--showLocationAddress--" type="checkbox" value="<%= showLocationAddress_cfg %>" />
<aui:input key="mailAddress" type="text" name="preferences--mailAddress--"/>
<aui:button-row>
<aui:button name="save-Boutton" type="submit" value="Save"/>
</aui:button-row>
</aui:form>
ConfigurationActionImpl.java is:
package com.nosester.portlet.eventlisting.action;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletPreferences;
import com.liferay.portal.kernel.portlet.DefaultConfigurationAction;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portlet.PortletPreferencesFactoryUtil;
public class ConfigurationActionImpl extends DefaultConfigurationAction {
@Override
public void processAction(
PortletConfig portletConfig, ActionRequest actionRequest,
ActionResponse actionResponse) throws Exception {
super.processAction(portletConfig, actionRequest, actionResponse);
PortletPreferences prefs = actionRequest.getPreferences();
String mailAddress=prefs.getValue("mailAddress", "default");
System.out.println("address mail= "+mailAddress);
}
But in all cases the mail address displayed is: default.
Can someone help me to correct this code in order it can display what the user put in the text field?
Upvotes: 1
Views: 1612
Reputation: 4210
I believe actionRequest
is not getting updated with portletPreferences
values when you call processAction
method of DefaultConfigurationAction
. You may use code below to fetch it properly.
String portletResource = ParamUtil.getString(
actionRequest, "portletResource");
PortletPreferences portletPreferences =
PortletPreferencesFactoryUtil.getPortletSetup(
actionRequest, portletResource);
portletPreferences .getValue("mailAddress", "default");
Upvotes: 1