I am going to disable the button after clicked as describes Here
Here is my code, but it can't disable the button after clicked.
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title></title>
<script language="JavaScript" type="javascript">
function handleDisableButton(data) {
if (data.source.type != "submit") {
return;
}
switch (data.status) {
case "begin":
data.source.disabled = true;
break;
case "complete":
data.source.disabled = false;
break;
}
}
jsf.ajax.addOnEvent(handleDisableButton);
</script>
</h:head>
<h:body>
<h:form>
<h:inputText id="email" value="#{bean2.email}"/>
<h:commandButton id="saveBtn" action="#{bean2.showClicked}" value="send">
<f:ajax onevent="handleDisableButton"/>
</h:commandButton>
</h:form>
</h:body>
</html>
And the showClicked()
simply says clicked
:
@ManagedBean
@SessionScoped
public class Bean2 {
private String email;
public void showClicked(){
System.out.println("clicked");
}
//getter/setter for email
}
The code is exactly what he preferred.