How to override primefaces component api class with custom class

青春壹個敷衍的年華 提交于 2019-12-04 21:48:32

You've 2 options:

  1. Just put it in Java source folder of WAR project, maintaining the original package structure (thus, having exactly the same FQN). Classes in WAR have higher precedence in classloading over those in JARs in WAR's /WEB-INF/lib. So, if exactly the same class (by FQN) is encountered in WAR, then it will be loaded from WAR instead of from JAR (in this particular case, PrimeFaces' one).

  2. Register the component class in faces-config.xml of WAR project on <p:treeTable>'s component type:

    <component>
        <component-type>org.primefaces.component.TreeTable</component-type>
        <component-class>com.example.component.CustomTreeTable</component-class>
    </component>
    

    Also here, any component class registered in WAR's faces-config.xml has higher precedence over the one in JAR's faces-config.xml (in this particular case, PrimeFaces' one).

After some effort I have figured out a way how to solve my problem

I have written class which extends primefaces TreeTable class like below and implemented the method visitColumns as specified in the link (given in my question).

You have to override all the methods which calls visitColumns method in the child class.

Now register it in the faces-config.xml as below

 <component>
    <component-type>org.primefaces.component.TreeTable</component-type>
    <component-class>com.example.component.MyTreeTable</component-class>
 </component>  

I believe this is the simplest way and solved my problem. Answering my own question so that it may help others.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!