0
我創建了2個測試portlet myportlet1和myportlet2。這兩種描述是similiar,看起來像這樣在portlet.xml
首選項 - 公司範圍設置在Liferay中不起作用
<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);
}
什麼我做錯了?謝謝
謝謝!我可以使用在portletpreferences表中看到的ID,例如「LIFERAY_PORTAL」用於非常全局的設置嗎? – Dims
我沒有嘗試過,但似乎是這樣的源代碼,但爲此目的,最好使用PortletPreferencesFactoryUtil.getPortalPreferences(portletRequest);請注意「getPortal」而不是「getPortlet」。 –
謝謝!爲什麼他們沒有做一個共同的有組織的共享數據存儲? – Dims