salesforce
  1. salesforce-apex-actionstatus-component

apex:actionStatus Component

The apex:actionStatus is a Visualforce component in Salesforce that enables you to display a message or image to denote the status of a long-running operation. This component is especially useful for operations that may take a while to complete, as it provides immediate feedback to the user on the status of the operation.

Syntax

The syntax for the apex:actionStatus component is as follows:

<apex:actionStatus id="id" 
    startText="start message" 
    stopText="stop message" 
    startStyle="CSS style for start text" 
    stopStyle="CSS style for stop text">
    ...
</apex:actionStatus>

Example

Consider the following example in which an apex:actionStatus component is used to display a message when the user clicks on a button to perform a long-running operation. The stopText attribute displays the message "Operation completed" when the operation is finished.

<apex:page controller="MyController">
  <apex:form>
    <apex:actionStatus id="myStatus" stopText="Operation completed">
      <apex:facet name="start">
        <img src="{!$Resource.LoadingIcon}" alt="Loading...">
        <span>Performing operation...</span>
      </apex:facet>
    </apex:actionStatus>
    <apex:commandButton value="Perform Long-Running Operation" 
                        action="{!performOperation}" 
                        rerender="outputPanel" 
                        status="myStatus"/>
    <apex:outputPanel id="outputPanel">
      <!-- Result of long-running operation will be displayed here -->
    </apex:outputPanel>
  </apex:form>
</apex:page>

Output

When the user clicks on the "Perform Long-Running Operation" button, the apex:actionStatus component will display an image and the message "Performing operation...". Once the operation is completed, the message "Operation completed" will be displayed, instead of the loading message and image.

Explanation

The apex:actionStatus component is used to show a message or image during a long-running operation, and can be associated with a Visualforce component that is triggered by the operation, such as an apex:commandButton or apex:actionFunction. The startText attribute displays the message or HTML content in the component while the operation is running, and the stopText attribute displays the message or HTML content when the operation is completed.

Use

The apex:actionStatus component is useful when you want to give immediate feedback to the user during long-running operations in your Visualforce page. It provides a loading indicator or a message to the user indicating that the operation is in progress, and a message indicating that the operation is completed.

Important Points

  • The apex:actionStatus component can be associated with any component that triggers an action, including an apex:commandButton or an apex:actionFunction.
  • You can use CSS styles to style the text displayed in the apex:actionStatus component.
  • You can add an image or other HTML content to the apex:actionStatus component using the startText attribute.

Summary

The apex:actionStatus component in Visualforce provides immediate feedback to users during long-running operations. It can be associated with components that trigger actions, and provides a loading indicator and message to the user during the operation, as well as a message when the operation is completed. The component can be styled using CSS, and HTML content can be added to be displayed during the operation using the startText attribute.

Published on: