当用户向页面添加应用程序时,从类别显示列表中选择应用。

图1:用户从类别显示列表中选择应用程序。
Portlet的显示类别定义在组件类的metadata property。由于留言portlet允许用户相互通信,因此将其添加到Social类别。只允许一个留言板portlet添加到页面,因此还要将其定义为不可实例化的portlet。这种portlet只能在页面或站点上显示一次,具体取决于其范围。
打开GuestbookPortlet该类并修改组件类metadata properties以完成配置:
@Component(
immediate = true,
property = {
"com.liferay.portlet.display-category=category.social",
"com.liferay.portlet.instanceable=false",
"com.liferay.portlet.scopeable=true",
"javax.portlet.display-name=Guestbook",
"javax.portlet.expiration-cache=0",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/guestbookwebportlet/view.jsp",
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user",
"javax.portlet.supports.mime-type=text/html"
},
service = Portlet.class
)
com.liferay.portlet.display-category=category.social属性将Guestbook portlet的显示类别设置为Social。该com.liferay.portlet.instanceable=false属性指定“留言”Portlet不可实例化,因此只能将一个Portlet实例添加到页面中。在属性中javax.portlet.init-param.view-template,还将主要位置调整为view.jsp新的位置/guestbookwebportlet。
由于编辑了Portlet的元数据,因此必须先移除portlet并将其重新添加到页面,然后才能继续:
- Go to
localhost:8080in your web browser. - Sign in to your administrative account.
- The Guestbook portlet now shows an error on the page. Click its portlet menu (at the top-right of the portlet), then select Remove and click OK to confirm.
- Open the Add menu and select Applications.
- Open the Social category and drag and drop the Guestbook application onto the page.
现在,留言簿portlet出现在适当的类别中。
本文介绍如何通过修改组件类的元数据属性,将一个Portlet设置为不可实例化并限定其显示类别为社交。这确保了在页面上只能出现一个此类Portlet实例。
235

被折叠的 条评论
为什么被折叠?



