如何在Liferay本机Portlet上替换功能 [英] How to replace a function on a Liferay native portlet

查看:66
本文介绍了如何在Liferay本机Portlet上替换功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对Liferay Intallation随附的本地Liferay Portlet进行更改.如何通过钩子或类似方法将函数更改为自己的实现?

I am making a change to a native Liferay portlet, that comes with Liferay Intallation. How can I change a function to my own implementation by a hook or similar approach?

我已经阅读了如何设置前置条件和后置条件,以及如何实现接口的新实现,但是我不知道如何替换我想保留的portlet的随机类中的随机函数.

I have read how to make pre and post conditions and how to make new implementation of an interface, but I don't know how to just replace random function inside random class at a portlet that I want to keep otherwise as it is originally.

推荐答案

有几种方法可以修改本机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.

这篇关于如何在Liferay本机Portlet上替换功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆