如何替换 Liferay 本机 portlet 上的函数
我正在对 Liferay Intallation 附带的本机 Liferay portlet 进行更改。如何通过钩子或类似方法将函数更改为我自己的实现?
我已经阅读了如何创建前置条件和后置条件以及如何创建接口的新实现,但我不知道如何在我想保留的 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?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有多种方法可以修改原生 Liferay portlet 的功能。这是一个快速概述。
大多数挂钩功能是通过位于 /docroot/WEB-INF 目录中的 liferay-hook.xml 文件描述的。以下是最常用的方法。
自定义JSP
在 liferay-hook.xml 文件中,将以下子项添加到
此元素定义您要放置的位置要覆盖的 JSP。例如,您可能需要重写位于以下位置的文档库 portlet 的 view.jsp:
模型监听器
对于这个,您必须定义一个通常存储在的 Portal.property 文件,
并告诉
liferay-hook.xml
它的位置。下面是上面的一个例子,如果你想监听User的变化,比如你可以在属性中写入,
格式如下,
并且你的类应该实现
com.liferay.portal。 model.BaseModelListener
。在这里您可以监听添加、更新、删除等事件。
Extend\Overwrite Service
这里有一个类似的故事,在
liferay-hook.xml
的
元素中添加在这里,您的实现应该为特定服务扩展正确的包装类。例如,对于上面的示例,
您现在应该能够覆盖 UserService 的所有公共方法,例如
updateUser(..)
。Struts Actions 的定制
(仅在 Liferay 6.1 版本中可用)
以与扩展服务非常相似的方式,定义
的元素您需要扩展,
并且您将有权访问该请求并可以执行自定义操作。与自定义 JSP 结合使用非常强大。
祝你好运!
请务必检查与您所使用的 Liferay 版本的兼容性。
如果您需要更多控制,则需要使用 ext 插件。
There are several ways you can modify the functionality of a native Liferay portlet. Here is a quick overview.
Most hooked functionality is described through the liferay-hook.xml file located in your /docroot/WEB-INF directory. Here are the most common method.
Custom JSPs
In the liferay-hook.xml file, add the following child to
<hook/>
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:
Model Listeners
For this one you'll have to define a portal.property file typically stored at,
And tell
liferay-hook.xml
its location. The following is an example for the above,if you want to listen to changes in User, for example, you would write in the property,
Which is in the following format,
And your class should implement
com.liferay.portal.model.BaseModelListener
.Here you can listen to events such as Add, Update, Remove, and a few others.
Extend\Overwrite Service
A similar story here, in
liferay-hook.xml
in the<hook />
element addHere your implementation should extend the correct wrapper class for a particular service. For the example above, for instance, is
You should now be able to overwrite all the public methods for the UserService like
updateUser(..)
.Customization of Struts Actions
(Only available from Liferay 6.1 version)
In very similar fashion as extending services, define the elements for
<hook />
You'll need to extend,
and you'll have access to the request and can perform a custom action. Which is very powerful in conjunction with custom JSPs.
Good Luck!
Be sure to check compatibility with the version of Liferay you are using.
If you need even more control you would need to use the ext-plugin.