创建自定义commandButton和Input组件

时间:2014-09-23 17:00:04

标签: jsf jsf-2 primefaces custom-component

我尝试使用带有最新HTML5属性的UICommand实现自定义JS2命令按钮。但是,我如何处理动作和actionListener的归属? UICommand将保存它们的值,这是由JSF2运行时完成的,但我怎么能确切地知道在用户在#dec; encodeBegin方法&#39的渲染器类中激活按钮后我应该执行哪个bean的方法。 ;。 PrimeFaces commandButon渲染器类的源代码here很复杂。

1 个答案:

答案 0 :(得分:0)

在我看来,您需要扩展该类(CommandButton或CommandButtonRendered)并完全覆盖无法正常工作的方法。像这样的CommandButtonRenderer:

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.primefaces.component.commandbutton.CommandButtonRenderer;

/**
 *
 * @author nuno_marinho
 */
public class MyCommandButtonRenderer extends CommandButtonRenderer {

    @Override
    ...

}

或类似于CommandButton:

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.primefaces.component.commandbutton.CommandButtonRenderer;
import org.primefaces.component.commandbutton.CommandButton;

/**
 *
 * @author nuno_marinho
 */
public class MyCommandButton extends CommandButton {

    @Override
    ...

}

最后,您需要在faces-config.xml中定义组件的更改,如下所示:

<render-kit>
    <renderer>
        <component-family>org.primefaces.component</component-family>
        <renderer-type>org.primefaces.component.CommandButton</renderer-type>
        <renderer-class>com.yourpackage.commandButton.MyCommandButton</renderer-class>
    </renderer>
</render-kit>

我希望解释可以帮到你!