java - 自定义 liferay portlet 作为贯穿门户元素

标签 java liferay liferay-6 portlet spring-portlet-mvc

我想弄清楚如何在 Liferay 中制作一件事。我正在使用很多自定义 portlet,但遇到了一个问题。我希望将自定义 portlet 作为门户中的贯穿元素。例如,在我的门户 header 中将自定义“搜索栏”作为 portlet。但问题是我需要相同的实例,因为每次我浏览新页面时,每次都会是一个新实例。我是对的?我需要像单例这样的东西。我怎样才能用liferay做到这一点?当然,我怎样才能将 portlet 作为一个 through 元素呢?

最佳答案

查看 liferay-portlet.xml 和属性

<preferences-company-wide>
<preferences-unique-per-layout>
<preferences-owned-by-group>
<instanceable>

以下描述摘自http://www.liferay.com/dtd/liferay-portlet-app_6_1_0.dtd

Element : preferences-company-wide
Set the preferences-company-wide value to true if the preferences for the portlet are across the entire company. Setting 
 this value to true means the value for preferences-unique-per-layout and preferences-owned-by-group are not used. 
 The default value is false. For example, an administrator could set the preferences to an Announcements portlet that 
 would save a message in the portlet's preferences. This message would then be used across all pages for that company. 
 The portlet must not be instanceable because instanceable portlets have uniquely generated portlet ids. The default 
 behavior of the bundled Announcements portlet sets the instanceable value to true so that normal users cannot create 
 company wide messages. A future release would include permissions for the edit mode versus the view mode which 
 would allow an administrator to set the message while users would just view the message.

Element : preferences-unique-per-layout
Set the preferences-unique-per-layout value to true if the preferences for the portlet are unique across all pages. If set 
 to false, the preferences for the portlet are shared across all pages. The default value is true. The preferences-unique-
 per-layout element is used in combination with the preferences-owned-by-group element. See the comments for the 
 preferences-owned-by-group element for more information.

Element : preferences-owned-by-group
Set the preferences-owned-by-group value to true if the preferences for the portlet are owned by the group when the 
 portlet is shown in a group page. If set to false, the preferences are owned by the user at all times. The default value is 
 true. Suppose the Stocks portlet has preferences-unique-per-layout set to true and preferences-owned-by-group set to 
 false. Users can set a different list of stocks for every personal page. Users can set a different list of stocks for every 
 community page. Suppose the Stocks portlet has preferences-unique-per-layout set to false and preferences-owned-by-
 group set to false. Users can set one list of stocks to be shared across all personal pages. Users can set one list of stocks 
 to be shared across a community's set of pages. Suppose the Stocks portlet has preferences-unique-per-layout set to 
 true and preferences-owned-by-group set to true. Users can set a different list of stocks for every personal page. 
 Administrators set the portlet preferences for users in a community page. Administrators can set a different list of stocks 
 for every community page that are then shared by all users within a community. Suppose the Stocks portlet has 
 preferences-unique-per-layout set to false and preferences-owned-by-group set to true. Users can set one list of stocks 
 to be shared across all personal pages. Administrators set the portlet preferences for users in a community page. 
 Administrators can set one list of stocks to be shared by all users across a community's set of pages.

Element : instanceable
Set the instanceable value to true if the portlet can appear multiple times on a page. If set to false, the portlet can only 
 appear once on a page. The default value is false.

要在主题中嵌入 portlet,请查看(假设使用 Velocity)类 com.liferay.taglib.util.VelocityTaglib

com.liferay.taglib.util.VelocityTaglib.runtime(String portletName)
com.liferay.taglib.util.VelocityTaglib.runtime(String portletName, String queryString)
com.liferay.taglib.util.VelocityTaglib.runtime(String portletName, String queryString, String defaultPreferences)

速度主题模板中的示例用法是

$theme.runtime("myportlet")

编辑(每条评论的更多信息):

如果您的 portlet 在 liferay-portlet.xml 中有此属性组合

    <preferences-unique-per-layout>false</preferences-unique-per-layout>
    <preferences-owned-by-group>true</preferences-owned-by-group>
    <instanceable>false</instanceable>

它将是不可实例化的,并且在整个站点中的所有页面(preferences-unique-per-layout = false)中具有一组首选项(preferences-owned-by-group = true)。 您可以将其包含在您的主题中,假设 war 名称为 myportlets.war,portlet 名称为 search,并使用

$theme.runtime("search_WAR_myportlets")

您可以在网站的任何给定页面上配置首选项。

如果您的 portlet 必须是可实例化的,那么您甚至可以编写实例 ID

$theme.runtime("search_WAR_myportlets_INSTANCE_MYMADEUPINSTANCEID")

对于这两种情况,都回答“每次创建新的 portlet 副本时?”是不是。

最好尝试上述方法并亲自看看会发生什么。

关于java - 自定义 liferay portlet 作为贯穿门户元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32794460/

相关文章:

redirect - 如何让 Liferay 6.1.0 在找不到资源时始终重定向到 404 页面?

java - JacksonFeature 打破了 JsonIgnoreProperties

java - 如何将参数化 JUnit 测试运行器与使用 Spring 注入(inject)的字段一起使用?

java - Liferay Web 应用程序部署依赖项

liferay - Liferay 6.1 中的多个文件上传

java - 无法在 Struts2 Liferay Portlet 中将窗口状态设置为独占

url-rewriting - Liferay 资源 URL 和操作 URL 之间的参数差异

java - 从 onclicklistener android 访问变量

Java - 如何自动设置 img.getScaledInstance( ); 的宽度?

liferay - 我们如何识别Liferay DB中的站点模板和页面模板信息