Skip to content

Dave Helgerson

Salesforce Software Development and Consulting

Menu
  • Contact
  • Resume
Menu

Disable Visualforce Buttons When Processing – apex:actionStatus

December 27, 2013May 13, 2014

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.

active buttons
disabled buttons

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;
  }
}

Related

7 thoughts on “Disable Visualforce Buttons When Processing – apex:actionStatus”

  1. Máximo Júnior says:
    April 28, 2014 at 10:54 pm

    There is a problem, the page messages don’t appear. Do you know how to solve it?

    1. Ankit says:
      May 12, 2014 at 1:08 pm

      Even, I am facing the same error. Apex Page message are not coming when I put action status.

    2. daveh says:
      May 13, 2014 at 1:04 am

      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.

  2. Babu says:
    October 15, 2014 at 3:15 pm

    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.

    1. daveh says:
      October 26, 2014 at 8:27 pm

      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.

        public PageReference DoCancel() {
          PageReference MyPR = new ApexPages.PageReference('/apex/AnotherPage');
          MyPR.setRedirect(true);
          return MyPR;
        }
      
  3. Dharmendra P says:
    November 18, 2014 at 8:02 am

    The above code is calling my save method twice. This should stop on first custom validation error but won’t. Please help.

  4. Ranjan says:
    November 26, 2014 at 10:52 am

    Awesome !!! Works Perfect. Thank you Dave.

Comments are closed.

Super Clone Pro
© 2023 Dave Helgerson | Powered by Minimalist Blog WordPress Theme
 

Loading Comments...