且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Liferay本机Portlet上替换功能

更新时间:2023-12-01 23:50:46

有几种方法可以修改本机Liferay Portlet的功能.这是一个快速概述.

There are several ways you can modify the functionality of a native Liferay portlet. Here is a quick overview.

大多数挂钩功能是通过/docroot/WEB-INF目录中的liferay-hook.xml文件描述的.这是最常用的方法.

Most hooked functionality is described through the liferay-hook.xml file located in your /docroot/WEB-INF directory. Here are the most common method.

在liferay-hook.xml文件中,将以下子项添加到<hook/>

In the liferay-hook.xml file, add the following child to <hook/>

<custom-jsp-dir>/META-INF/custom_jsps</custom-jsp-dir>

此元素定义要放置要覆盖的JSP的位置.例如,您可能想在以下位置为文档库Portlet重写view.jsp:

This element defines the location of where you are going to place JSPs to be overwritten. For example you may want to rewrite view.jsp for the Document Library portlet at:

[custom-jsp-dir]/html/portlet/document_library/view.jsp

Model Listeners

For this one you'll have to define a portal.property file typically stored at,

/docroot/WEB-INF/src/portal.property

并告诉liferay-hook.xml它的位置.以下是上述示例,

And tell liferay-hook.xml its location. The following is an example for the above,

<portal-properties>portal.properties</portal-properties>

例如,如果您想听用户中的更改,则可以在属性中编写

if you want to listen to changes in User, for example, you would write in the property,

value.object.listener.com.liferay.portal.model.User=com.my.example.UserListener;

采用以下格式,

value.object.listener.[class-to-listen]=[my-listener-class]

您的课程应该实现com.liferay.portal.model.BaseModelListener.

在这里您可以收听添加,更新,删除和其他一些事件.

Here you can listen to events such as Add, Update, Remove, and a few others.

这里有一个类似的故事,在liferay-hook.xml<hook />元素中添加

A similar story here, in liferay-hook.xml in the <hook /> element add

<service>
    <service-type>com.liferay.portal.service.UserService</service-type>
    <service-impl>my.example.service.UserServiceImpl</service-impl>
</service>

在这里,您的实现应为特定服务扩展正确的包装器类.例如,对于上面的示例,

Here your implementation should extend the correct wrapper class for a particular service. For the example above, for instance, is

com.liferay.portal.service.UserServiceWrapper;

您现在应该能够覆盖UserService的所有公共方法,例如updateUser(..).

You should now be able to overwrite all the public methods for the UserService like updateUser(..).

以与扩展服务非常相似的方式,定义<hook />

In very similar fashion as extending services, define the elements for <hook />

<struts-action>
    <struts-action-path>/message_boards/view</struts-action-path>
    <struts-action-impl>my.example.action.SampleViewAction</struts-action-impl>
</struts-action>

您需要扩展

com.liferay.portal.kernel.struts.BaseStrutsAction

,您将有权访问该请求并可以执行自定义操作.与自定义JSP结合使用时,该功能非常强大.

and you'll have access to the request and can perform a custom action. Which is very powerful in conjunction with custom JSPs.

请确保检查与您使用的Liferay版本的兼容性.

Be sure to check compatibility with the version of Liferay you are using.

如果您需要更多控制权,则需要使用ext-plugin.

If you need even more control you would need to use the ext-plugin.