【问题标题】:Interacting with Liferay portlet configuration in the portlet class在 portlet 类中与 Liferay portlet 配置交互
【发布时间】:2015-06-16 01:05:23
【问题描述】:

在 Liferay 6.0 插件 MVC portlet 中,如何从 portlet 类访问 portlet 配置?

请注意,“配置”是指特定于 portlet 实例且用户特定的值;如果管理员设置了 portlet 配置值,它应该对所有用户生效。

例如:

public class MyPortlet extends MVCPortlet
{
  @Override
  public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
    throws IOException, PortletException
  {
    // Fill in the blank; what goes here?
    String configValue = ?;

    renderRequest.setAttribute("some-key", configValue);        

    super.doView(renderRequest, renderResponse);
  }
}

【问题讨论】:

    标签: plugins liferay-6 portlet


    【解决方案1】:

    您可以利用 Liferay 的 PortletPreferences 服务来完成此操作:

    String portletInstanceId = (String) renderRequest.getAttribute(WebKeys.PORTLET_ID);
    
    PortletPreferences config = PortletPreferencesFactoryUtil.getPortletSetup(request, portletInstanceId);
    
    // To retrieve a value from configuration:
    String value = config.getValue("key", "default value");
    
    // To store a value:
    config.setValue("key", newValue);
    config.store();
    

    这有点令人困惑,因为它被命名为 PortletPreferences(暗示特定于用户的首选项)而不是类似 PortletConfiguration(暗示管理员控制的全局配置)...所以只需将其视为 portlet 实例的首选项不特定于任何用户。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多