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;
}
}
There is a problem, the page messages don’t appear. Do you know how to solve it?
Even, I am facing the same error. Apex Page message are not coming when I put action status.
You will need to rerender the tag that contains apex:pageMessages or the apex:pageMessages tag itself. I have updated the post to show an example.
I have command button that I want disable it while it is processing and after processing I want to redirect it to different page? Can you help me please.
In the example, the button returns a null PageReference. This refreshes the page. You could return a PageReference to a new page, and the user would be redirected.
The above code is calling my save method twice. This should stop on first custom validation error but won’t. Please help.
Awesome !!! Works Perfect. Thank you Dave.