如何识别托管bean中单击的commandButton [英] How to identify clicked commandButton in my managed bean
本文介绍了如何识别托管bean中单击的commandButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的托管bean中有一个actionListener
方法,该方法被许多命令按钮调用.
I have an actionListener
method in my managed bean which is called by many command buttons.
public void verifyTestDisponibility(ActionEvent actionEvent) {
if (button1 clicked) {
// ...
}
if (button2 clicked) {
// ...
}
}
我停留的部分是识别单击的命令按钮.如何识别?
The part I'm stucking at is identifying the clicked command button. How can I identify it?
推荐答案
您可以像这样使用它
在xhtml页面中,我们可以将<h:commandButton>
标记与actionListener一起使用
In xhtml page we can use a <h:commandButton>
tag with actionListener
<h:commandButton id="btn1" action="#{yourBean.method}" value="ButtonValue"
actionListener="#{yourBean.commandClicked}"></h:commandButton>
在您的托管bean中
private String buttonId;
/* getters and setters for buttonId goes here */
public void commandClicked(ActionEvent event) {
/* retrieve buttonId which you clicked */
buttonId = event.getComponent().getId();
/*check for which button you clicked*/
if(buttonId.equals("btn1")){
}else{
}
}
这篇关于如何识别托管bean中单击的commandButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文