我想要覆盖SearchResultsPortlet.java的一些方法。 Liferay/dxp-7.4.13-u76

huangapple go评论70阅读模式
英文:

I want to override some methods of SearchResultsPortlet.java. Liferay/dxp-7.4.13-u76

问题

I am trying to achieve this through liferay module fragment. Is it possible?
我正在尝试通过Liferay模块片段来实现这个。这可行吗?

I created a fragment and created the packages with exact names as they have in source code.
我创建了一个片段,并创建了与源代码中完全相同的包。

I created a public class CustomPortlet extends SearchResultsPortlet.
我创建了一个名为CustomPortlet的公共类,继承自SearchResultsPortlet

I implemented a @Override public void render(RenderRequest rq,RenderResponse re ) throws IOException,PortletException {log.info("Overriden"); System.out.println("Overriden"); super.render(rq,re);}
我实现了一个@Override方法,名为render,它接受RenderRequest rqRenderResponse re参数,并抛出IOException和PortletException异常。方法中包含日志记录和打印信息的操作。

I also tried with and without @Component annotation in my subclass.
我还尝试在我的子类中使用和不使用@Component注解。

But osgi is not registering my component.
但是OSGi没有注册我的组件。

What am I doing wrong? Do I need to add properties inside @Component annotation? Shouldn't the subclass inherit the superclass's annotations? I also made changes in a few jsp files, they are reflected in the portlet.
我做错了什么?我需要在@Component注解内添加属性吗?子类不应该继承超类的注解吗?我还在一些JSP文件中进行了更改,这些更改在Portlet中反映出来。

英文:

I am trying to achieve this through liferay module fragment. Is it possible?

I created a fragment and created the packages with exact names as they have in source code.

I created a public class CustomPortlet extends SearchResultsPortlet.

I implemented a @Override public void render(RenderRequest rq,RenderResponse re ) throws IOException,PortletException {log.info("Overriden");
System.out.println("Overriden"); super.render(rq,re);}

I also tried with and without @Component annotation in my subclass.
But osgi is not registering my component.
What am I doing wrong? Do I need to add properties inside @Component annotation? Shouldn't the subclass inherit the superclass's annotations? I also made changes in a few jsp files, they are reflected in the portlet.

答案1

得分: 1

以下是翻译的内容:

有几个问题似乎存在:

  • 片段捆绑包可以包含JSP文件,但不能包含代码、组件等。
  • 仅仅因为你实现了一个portlet的子类,并不意味着它会被连接到超类组件而不是替换掉。

不要提供完整的教程来解决这个问题:我的建议是寻找解决底层问题的解决方案。你选择了一种解决策略(覆盖一个portlet),这可能或可能不是底层问题的适当解决方案:Liferay的搜索框架提供了许多扩展点,用于扩展而不是需要替换的代码。

如果你想坚持使用你的解决方案,请搜索“marketplace override”,它基本上允许你替换内置组件。但我不建议这样做,因为每次更新时你都必须进行三方合并,原始组件已经更改。这会带来很大的维护负担,我认为一定有更简单的解决方案(只是我不知道你的底层问题是什么)。

英文:

There seem to be several issues:

  • Fragment bundles can contain JSPs but not code, Components, etc.
  • Just because you implement a subclass of a portlet does not mean that it'll be wired instead of the superclass component

Instead of providing a full tutorial how to do it: My recommendation is to check for a solution to the underlying problem. You have chosen a solution strategy (override a portlet), which may or may not be the proper solution for the underlying problem: Liferay's Search framework provides a lot of extension points that are meant for extention rather than code that needs to be replaced

If you want to stick with your solution, search for "marketplace override", which basically allows you to replace built-in components. I'd not recommend it though, as you'll have to do a three-way-merge any time you update and the original component has changed. That's a lot of maintenance burden, and I assume that there must be simpler solutions (I just don't know your underlying problem)

huangapple
  • 本文由 发表于 2023年5月21日 12:09:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76298264.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定