<apex: actionFunction> Component in Visualforce Page

The <apex:actionFunction> component is one of the most used components to invoke the controller's action methods from the JavaScript code directly by using an AJAX request.

This component should always be the child component of the <apex:form> because binding between the caller and the <apex:actionFunction> component is done based on parameter order. We have to ensure the order of the <apex:param> matches the caller's argument list.

The <apex:actionFunction> is different from the <apex:actionSupport>. The <apex:actionSupport> invokes controller action methods from other VF components. However, the <apex:actionFunction> defines a new JavaScript function that can be called from within a block of JS code.

The <apex:actionFunction> component has the following attributes:

1. action

The action attribute is of type string that defines the action method invoked when the <apex:actionFunction> is called by the DOM event elsewhere in the page markup.

Syntax

2. focus

The focus attribute is of type string that defines the id of the component that is in focus after the AJAX request completes.

Syntax

3. id

The id attribute is of type string that is a unique identifier allowing the <apex:actionFunction> component to be referenced by other components on the page.

Syntax

4. immediate

The immediate attribute is of type Boolean. If its value is true, the action associated with the component will happen immediately. The function will not process the validation rules associated with the fields on the page.

Syntax

5. name

The name attribute is of type string that is used for defining the name of the JavaScript function.

Syntax

6. namespace

The namespace attribute is of type string that is used for defining the namespace, i.e., to be used for the generated JavaScript function.

Syntax

7. timeout

The timeout attribute is of type Integer that defines the amount of time before an AJAX update request should time out.

Syntax

8. status

The status attribute is of type string that defines the Id of an associated component that displays the status of an AJAX update request.

Syntax

9. reRender

The reRender attribute is of type Object that is Id of one or more components which we need to redraw when the client receives the result of the action method.

Its value can be a single Id, comma-separated Id, or a collection of Ids.

Syntax

10. rendered

A Boolean attribute is used to specify whether the component is rendered on the page or not. By default, its value is set to true.

Syntax

11. oncomplete

String type attribute that defines the JavaScript method invoked when the result of an AJAX update request completes on the client.

Syntax

12. onbeforedomupdate

Another string type attribute that defines the JavaScript method invoked when the onbeforedomupdate event occurs.

Syntax

Let's take an example to understand how we can use the apex actionFunction in the code:

ApexActionFunctionExample.vfp

ApexActionFunctionController.apxc

Output

apex:actionFunction component in Visualforce Page




Latest Courses