偏好 - 公司范围的设置在Liferay中不起作用

时间:2011-12-02 12:14:37

标签: java liferay preferences portlet sharing

我创建了2个测试portlet,myportlet1和myportlet2。两个描述都类似,在portlet.xml

中看起来像这样
<portlet>
    <portlet-name>myportlet1</portlet-name>
    <display-name>MyPortlet1</display-name>
    <portlet-class>com.inthemoon.tests.MyPortlet1</portlet-class>
    <init-param>
        <name>view-jsp</name>
        <value>/html/myportlet1/view.jsp</value>
    </init-param>
    <expiration-cache>0</expiration-cache>
    <supports>
        <mime-type>text/html</mime-type>
        <portlet-mode>VIEW</portlet-mode>
    </supports>
    <portlet-info>
        <title>MyPortlet1</title>
        <short-title>MyPortlet1</short-title>
        <keywords></keywords>
    </portlet-info>
    <portlet-preferences>
        <preference>
            <name>testPreferenceForMyPortlet1</name>
            <value>C:\WINDOWS1</value>
        </preference>
    </portlet-preferences>
    <security-role-ref>
        <role-name>administrator</role-name>
    </security-role-ref>
    <security-role-ref>
        <role-name>guest</role-name>
    </security-role-ref>
    <security-role-ref>
        <role-name>power-user</role-name>
    </security-role-ref>
    <security-role-ref>
        <role-name>user</role-name>
    </security-role-ref>
</portlet>

并在liferay-portlet.xml

中这样
<portlet>
    <portlet-name>myportlet1</portlet-name>
    <icon>/icon.png</icon>
    <preferences-company-wide>true</preferences-company-wide>
    <instanceable>false</instanceable>
    <header-portlet-css>/css/main.css</header-portlet-css>
    <footer-portlet-javascript>
        /js/main.js
    </footer-portlet-javascript>
    <css-class-wrapper>myportlet1-portlet</css-class-wrapper>
</portlet>

区别在于索引。

因此,如您所见,这两个portlet都不可实现,并设置为在公司范围内共享其首选项。

尽管如下,以下代码显示每个portlet只知道它自己的首选项,但不知道其他portlet的首选项:

@Override
public void doView(RenderRequest renderRequest,
        RenderResponse renderResponse) throws IOException, PortletException {

    javax.portlet.PortletPreferences prefs1 = renderRequest.getPreferences();
    //com.liferay.portal.model.PortletPreferences prefs2 = PortletPreferencesLocalServiceUtil.

    String portletResource = ParamUtil.getString(renderRequest, "portletResource");
    if (Validator.isNotNull(portletResource)) {
        try {
            prefs1 = PortletPreferencesFactoryUtil.getPortletSetup(renderRequest, portletResource);
        } catch (SystemException e) {
            e.printStackTrace();
        }
    }

    String testPreferenceForMyPortlet1 = prefs1.getValue("testPreferenceForMyPortlet1", "(not set)");
    String testPreferenceForMyPortlet2 = prefs1.getValue("testPreferenceForMyPortlet2", "(not set)");

    renderRequest.setAttribute("testPreferenceForMyPortlet1", testPreferenceForMyPortlet1);
    renderRequest.setAttribute("testPreferenceForMyPortlet2", testPreferenceForMyPortlet2);

    renderRequest.setAttribute("prefs1", prefs1);

    super.doView(renderRequest, renderResponse);
}

我做错了什么?感谢

1 个答案:

答案 0 :(得分:2)

'问题'是preferences-company-wide没有告诉偏好将与不同的portlet共享。

它的用途是在单个portlet中共享首选项,但在不同的社区/组织/ user_pages ...(不同的组ID)中。

要获得其他portlet的首选项,您必须使用

PortletPreferencesFactoryUtil.getPortletSetup(portletRequest, "another portlet's id");