actionstatus visualforce salesforce

actionStatus visualforce salesforce

actionStatus visualforce component displays the status of an AJAX update request. An AJAX request can either be in progress or complete.

Depending upon the AJAX request status (whether AJAX request is in progress or complete), this component will display different message to user. In many scenarios AJAX request takes some time. So we should display some message to user that your request is in progress. Once request is complete, we can display some different message to user.

Using actionstatus, we can also display some gif (graphic Interchange Format), which shows to user that their request is in progress. It gives very good presentation to end user.

In the example below, we are using actionSupport component for AJAX request. You can see my previous post to know more about actionsupport component. In this example we are showing some text message to user while AJAX request is in progress using actionstatus component. It shows some different message once request is complete.

When user will click on ‘Click here for increment’ or ‘Click here for decrement’, then count will be incremented or decremented accordingly. Also when request is in progress, message will be shown to user.

Click for Demo

Visualforce Code:

<apex:page controller="actionSupportController">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:outputpanel id="panel1">
                    <apex:outputText value="Click here to increment!"/>
                    <apex:actionSupport event="onclick" action="{!incrementCounter}" rerender="out" status="counterStatus"/>
                    <apex:actionStatus id="counterStatus" startText=" (incrementing...)" stopText=" (done)"/>
                </apex:outputpanel>

                <apex:outputpanel id="panel2">
                    <apex:outputText value="Click here to decrement!"/>
                    <apex:actionSupport event="onclick" action="{!decrementCounter}" rerender="out" status="counterStatus2"/>
                    <apex:actionStatus id="counterStatus2" startText=" (decrementing...)" stopText=" (done)"/>
                </apex:outputpanel>

                <apex:outputText value="{!count}" id="out" label="Count Is:"/>

            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex Code:

public class actionSupportController {
    Integer count = 0;

    public PageReference incrementCounter() {
            count++;
            return null;
    }

    public PageReference decrementCounter() {
            count--;
            return null;
    }

    public Integer getCount() {
        return count;
    }
}

Permanent link to this article: https://www.sfdcpoint.com/salesforce/actionstatus-visualforce-salesforce/

Leave a Reply

Your email address will not be published.