我的actionListener托管bean中有一个方法,由许多命令按钮调用.
public void verifyTestDisponibility(ActionEvent actionEvent) {
if (button1 clicked) {
// ...
}
if (button2 clicked) {
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
我正在坚持的部分是识别点击的命令按钮.我该如何识别它?
你可以像这样使用它
在xhtml页面中,我们可以使用<h:commandButton>带有actionListener 的标记
<h:commandButton id="btn1" action="#{yourBean.method}" value="ButtonValue"
actionListener="#{yourBean.commandClicked}"></h:commandButton>
Run Code Online (Sandbox Code Playgroud)
在您的托管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{
}
}
Run Code Online (Sandbox Code Playgroud)