创建自定义commandButton和Input组件(Create a custom commandButton and Input components)

编程入门 行业动态 更新时间:2024-10-25 22:34:40
创建自定义commandButton和Input组件(Create a custom commandButton and Input components)

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

I'm trying to implement a custom JS2 command button using UICommand with the latest HTML5 attributes. But, how i can handles the action and actionListener attribues? The UICommand will save thier values, this done by the JSF2 runtime, but how i can know exactly which methode of which bean that i should excute after the button activation by the user in the renderer class at the 'encodeBegin methode'. The source code for the PrimeFaces commandButon renderer class, available here is complicated.

最满意答案

在我看来,您需要扩展该类(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>

我希望解释可以帮到你!

In my opinion, you need extend that class (CommandButton or CommandButtonRendered) and override exactly the methods that does not work as you want. Like this for 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 ... }

or like this for 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 ... }

And finally you need define the changes for component in faces-config.xml like this:

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

I hope that explaination can help you!

更多推荐

本文发布于:2023-08-04 23:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1423289.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   组件   commandButton   components   Input

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!