如何重写Primefaces组件类

如何重写Primefaces组件类

本文介绍了如何重写Primefaces组件类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重写primefaces组件类.因此,我已经在WAR项目的faces-config.xml中注册了组件类.

I would like to override a primefaces component class. So, I have registered the component class in faces-config.xml of WAR project.

    <component>
        <component-type>org.primefaces.component.dnd.Droppable</component-type>
        <component-class>com.******.****.****.component.CustomDroppable</component-class>
    </component>

这是我的新测试班:

public class CustomDroppable extends Droppable{

    @Override
    public void queueEvent(FacesEvent event) {
        System.out.print("fffffffffffff");
    }

}

该应用程序是重新构建的,但它使用的是旧类.为什么 ?我该怎么办?

The application was built anew, but it uses the old class. Why ? What else should I do ?

推荐答案

<component-type>中,应指定组件类型,而不是组件类.组件类型不一定类似于Java FQN,它可以是您想要的任何类型的字符串.通常,您可以在要替换的组件类的API文档中找到合适的组件类型.

In the <component-type>, you should specify the component type, not the component class. The component type does not necessarily resemble a Java FQN, it can be any kind of string you want. Usually, you can find the right component type in the API documentation of the component class you'd like to replace.

对于 org.primefaces.component.dnd.Droppable 类,它被定义为常量字段 COMPONENT_TYPE ,其值为 org.primefaces.component.Droppable (因此,与组件类相比,没有dnd" subpackage.

In case of org.primefaces.component.dnd.Droppable class, it's defined as constant field COMPONENT_TYPE whose value is org.primefaces.component.Droppable (thus, without dnd "subpackage" as compared to the component class).

相应修复:

<component>
    <component-type>org.primefaces.component.Droppable</component-type>
    <component-class>...</component-class>
</component>

另请参见:

  • 组件族,组件类型和渲染器类型?
  • See also:

    • What is the relationship between component family, component type and renderer type?
    • 这篇关于如何重写Primefaces组件类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 17:49