自定义liferay portlet作为一个通道门户元素

时间:2015-09-26 06:47:49

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

我想知道如何在Liferay中制作一件事。我使用了很多自定义portlet并遇到了问题。我希望将自定义portlet作为门户网站中的直通元素。例如,我的门户网站标题中的自定义“搜索栏”作为portlet。但问题是我需要相同的实例,因为每当我要浏览新页面时,每次它都是一个新实例。我是正确的?我需要像单身人士这样的东西。我怎么能用liferay做到这一点?当然,我如何将portlet作为直通元素?

1 个答案:

答案 0 :(得分:2)

查看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)。 你可以把它包含在你的主题中,假设战争名称是myportlets.war,portlet名称是搜索,带

$theme.runtime("search_WAR_myportlets")

您可以在网站的任何指定页面上提供偏好设置。

如果你的portlet必须是实例的,你甚至可以编写实例id

$theme.runtime("search_WAR_myportlets_INSTANCE_MYMADEUPINSTANCEID")

对于这两种情况,每次创建新的portlet副本时都回答&#34;&#34;不是。

最好尝试abowe方法,亲眼看看会发生什么。