如何使用自定义类覆盖primefaces组件api类 [英] How to override primefaces component api class with custom class

查看:139
本文介绍了如何使用自定义类覆盖primefaces组件api类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临p:treeTable中列的重复ID,即与以下链接

I am facing the duplicate ids for columns issue in p:treeTable i.e. same problem as described in the below link

http://forum.primefaces. org/viewtopic.php?f = 3& t = 31158& p = 99463#p99463

因此,我想按照上述解决方案中的建议实施解决方案.因此,我想到了更改源代码并重新编译和使用jar的方法,但是我没有获得执行此操作的权限.我被要求通过扩展org.primefaces.component.api.UITree类或以某种方式自定义类,而无需更改primefaces jar中的实际类.

So I would like to implement the solution as suggested in the above solution. So I thought of changing the source code and recompile and use the jar but I haven't got permission to do the same. I was asked to customise the class by extending the org.primefaces.component.api.UITree class or somehow without changing the actual class in primefaces jar.

所以现在假设我创建了一个具有相同名称的UITree的类,并为我做了必要的更改.无论如何,要注册该类,以便可以使用我的类代替primefaces类

So now assume I have created a class with same name UITree and made necessary changes for me. Is there anyway to register this class so that my class can be used instead of primefaces class

推荐答案

您有2个选项:

  1. 只需将其放在WAR项目的Java源文件夹中,并保持原始的包结构(因此,具有完全相同的FQN). WAR中的类在类加载中的优先级高于WAR /WEB-INF/lib中的JAR中的类.因此,如果在WAR中遇到完全相同的类(通过FQN),那么它将从WAR而不是从JAR加载(在这种情况下,是PrimeFaces的一个).

  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).

<p:treeTable>的组件类型上将组件类注册到WAR项目的faces-config.xml中:

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>

此外,在WAR的faces-config.xml中注册的任何组件类都比JAR的faces-config.xml中的组件类(在这种情况下为PrimeFaces的)具有更高的优先级.

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).

这篇关于如何使用自定义类覆盖primefaces组件api类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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