gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 08:46:39 25 4
gpt4 key购买 nike

我想弄清楚如何在 Liferay 中制作一件东西。我使用了很多自定义 portlet 并遇到了问题。我想让我的自定义 portlet 作为门户中的直通元素。例如,在我的门户标题中将“搜索栏”自定义为 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)类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-owned-by-group=true)中的所有页面(preferences-unique-per-layout=false)将具有一组首选项。您可以将它包含在您的主题中,假设 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com