使用PortletKeys
在一个地方管理重要的东西,比如如portlet名称或其他可重复使用的常量。这样,如果需要更改portlet的名称,可以在一个地方完成,然后在需要它的每个类中引用。Keys必须首先被组件属性引用,然后被类引用。
按照以下步骤创建应用程序PortletKeys
:
- In your
guestbook-web
module, open theGuestbookPortlet
class and update the component class metadata properties by adding one new property:"javax.portlet.name=" + GuestbookPortletKeys.GUESTBOOK,
Note that you need the trailing comma if you’ve added the property to the middle of the list. If you’ve added it to the end of the last, leave it off.
- Save
GuestbookPortlet
. It now shows an error because you haven’t added the key to the class. - Open the
com.liferay.docs.guestbook.constants
package. - Open
GuestbookPortletKeys
and create a public, static, final String calledGUESTBOOK
with a value ofcom_liferay_docs_guestbook_portlet_GuestbookPortlet
:public static final String GUESTBOOK = "com_liferay_docs_guestbook_portlet_GuestbookPortlet";
- Save the file.
现在GuestbookPortlet
的错误已经消失,应用程序可以重新部署。
接下来,将应用程序与使用Service Builder生成的新后端集成。