Liferay portlet配置

时间:2014-07-10 12:24:45

标签: java liferay-6

我试图个性化Liferay portlet的配置。

configuration.jsp是:

<%@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是:

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);
        }

但在所有情况下,显示的邮件地址为:default。

有人可以帮我纠正这段代码,以便能显示用户在文字栏中输入的内容吗?

1 个答案:

答案 0 :(得分:1)

当您调用actionRequest portletPreferences方法时,我认为processAction未使用DefaultConfigurationAction值进行更新。您可以使用以下代码正确获取它。

 String portletResource = ParamUtil.getString(
        actionRequest, "portletResource");

 PortletPreferences portletPreferences =
        PortletPreferencesFactoryUtil.getPortletSetup(
            actionRequest, portletResource);

 portletPreferences .getValue("mailAddress", "default");