我正在尝试使用具有最新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!
更多推荐
发布评论