It is very handy to disable buttons after they have been pressed. This lets the user know that the button was in fact pressed, and it prevents the button’s action from being executed multiple times. The Visulforce component apex:actionStatus gives us an easy way to accomplish this. Here are some things to take note of in the example.
- The command button must have a rerender parameter
- Command buttons must be in an apex:outputPanel, so both buttons appear on the page when each apex:facet is active.
- The action status will only disable one set of buttons for a apex:pageBlock at a time. If ‘both’ is specified for the button location, only the clicked set of buttons on top or bottom will be disabled while processing. I usually select only one location to prevent additional button clicks.
- Add the immediate=”true” attribute to the Cancel. This bypasses Visualforce validation that would normally fire on the form.
ExamplePage.page
ExamplePageController.cls
public with sharing class ExamplePageController {
public ExamplePageController() {
// do constructor logic
}
public PageReference DoSave() {
// do save logic
return null;
}
public PageReference DoCancel() {
// do cancel logic
return null;
}
}