自定义 liferay portlet 作为直通门户元素

Custom liferay portlet as a throught portal element

我想弄清楚如何在 Liferay 中制作一件事。我使用了很多自定义 portlet 并遇到了问题。我想让我的自定义 portlet 作为门户中的直通元素。例如,在我的门户 header 中自定义 "searchbar" 作为 portlet。但问题是我需要同一个实例,因为每次我浏览新页面时,每次都会是一个新实例。我是对的?我需要像单身人士这样的东西。我怎样才能用 liferay 做到这一点?当然,我怎样才能使 portlet 成为直通元素?

看看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)class 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)

velocity 主题模板中的示例用法为

$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-owned-by-group=true)中的所有页面(preferences-unique-per-layout=false)将只有一组首选项。 您可以将它包含在您的主题中,假设 war 名称是 myportlets.war 并且 portlet 名称是搜索,

$theme.runtime("search_WAR_myportlets")

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

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

$theme.runtime("search_WAR_myportlets_INSTANCE_MYMADEUPINSTANCEID")

对于这两种情况,"every time new copy of portlet will be created?" 的答案是否定的。

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