How to Use Apex:actionSupport tag in Visualforce Page | Techila
2190
single,single-post,postid-2190,single-format-standard,ajax_updown_fade,page_not_loaded,,qode_grid_1300,footer_responsive_adv,hide_top_bar_on_mobile_header,qode-content-sidebar-responsive,qode-theme-ver-9.4.2,bridge,wpb-js-composer js-comp-ver-4.12,vc_responsive
 

How to Use Apex:actionSupport tag in Visualforce Page

APEX:ACTIONSUPPORT TAG IN VISUALFORCE

How to Use Apex:actionSupport tag in Visualforce Page

<apex:actionSupport> 

A component that adds AJAX support to another component, allowing the component to be refreshed asynchronously by the server when a particular event occurs, such as a button click or mouseover.

actionSupport component adds AJAX support to other components in visualforce. It allows components to be refreshed asynchronously by calling the controller’s method when any event occurs (like click on button). It allows us to do partial page refresh asynchronously without refreshing  full page.

In the example below, initially count value is set to 0. But when we will click on ‘Click here to increment! ‘, then controller action method will be called and count will be incremented. Also outputText component will be rendered without refreshing complete page.

Similarly when we will click on ‘Click here to decrement!’, then controller action method will be called and count will be decremented. Also outputText component will be rendered without refreshing complete page.

apex:actionSupport has following attributes in our example:

  • action: action attribute specifies the controllers action method that will be invoked when event occurs.
  • event: It is DOM event that generates AJAX request
  • reRender: It is comma separated id’s of components that needs to be partially refreshed. In our example, we have given its value as ‘out’. So component with ‘out’ id will be refreshed without refreshing complete page.

 Example:

<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”/>
                </apex:outputpanel>

                <apex:outputpanel id=”panel2″>
                    <apex:outputText value=”Click here to decrement!”/>
                    <apex:actionSupport event=”onclick” action=”{!decrementCounter}” rerender=”out”/>
                </apex:outputpanel>

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

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

Controller : 

public class actionSupportController {
    Integer count = 0;

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

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

    public Integer getCount() {
        return count;
    }
}

Courtesy: http://sfdcsrini.blogspot.com/2015/02/how-to-use-apexactionsupport-tag-in.html

“Explore – Techila Global Services, A Salesforce development company”

Author: techila

No Comments

Post A Comment