salesforce
  1. salesforce-apex-actionsupport-component

apex:actionSupport Component

The apex:actionSupport component is a Visualforce component in Salesforce that allows you to update a Visualforce page based on a user action, such as clicking a button or selecting a value from a dropdown. It provides a way to implement AJAX without the need for writing custom JavaScript code.

Syntax

Here is the basic syntax for the apex:actionSupport component:

<apex:actionSupport event="eventName" action="{!controllerMethod}" rerender="componentId" />
  • event - the DOM event that triggers the action.
  • action - the controller method that is called when the action is triggered.
  • rerender - the ID of the component(s) that should be refreshed when the action is completed.

Example

Consider the following example that uses apex:actionSupport to update a Visualforce page when a user selects a value from a dropdown:

<apex:page controller="MyController">
  <apex:form>
    <apex:selectList value="{!selectedOption}" size="1">
      <apex:selectOption itemLabel="Option 1" itemValue="Option 1" />
      <apex:selectOption itemLabel="Option 2" itemValue="Option 2" />
      <apex:selectOption itemLabel="Option 3" itemValue="Option 3" />
      <apex:actionSupport event="onchange" action="{!updateValue}" rerender="outputPanel" />
    </apex:selectList>
  </apex:form>
  <apex:outputPanel id="outputPanel">
    <apex:outputText value="{!selectedOption}" />
  </apex:outputPanel>
</apex:page>

Here, the apex:actionSupport component is used to trigger the updateValue method in the controller when the user selects a value from the dropdown. The outputPanel component is then refreshed to display the updated value.

Explanation

When a user selects a value from the dropdown, the onchange event is triggered, which in turn triggers the updateValue method in the controller. The selectedOption variable is then updated with the selected value, and the outputPanel component is refreshed to display the updated value.

Use

The apex:actionSupport component is useful when you want to update a Visualforce page based on user input without having to reload the entire page. This can improve the user experience by making the page more responsive and interactive.

Important Points

  • The apex:actionSupport component should be used in conjunction with other Visualforce components that can be refreshed, such as <apex:outputPanel>, <apex:pageBlock>, or <apex:pageBlockSection>.
  • The event attribute should match the DOM event that triggers the action, such as onchange or onclick.
  • The action attribute should specify the name of the controller method that handles the action.
  • The rerender attribute should specify the ID of the component(s) that should be updated when the action is triggered.

Summary

The apex:actionSupport component is a useful Visualforce component in Salesforce that enables AJAX functionality without having to write custom JavaScript code. It is often used to update a Visualforce page based on user input, such as clicking a button or selecting a value from a dropdown. The event, action, and rerender attributes are important to specify when using this component, and it should be used in conjunction with other Visualforce components that can be refreshed.

Published on: