Last night(July 17th, 2019) while preparing for Platform Developer II certification, I was going through my notes to revise the different ways to call Apex Controller functions from Visualforce page, I thought of making a post regarding actionRegion, actionFunction, actionSupport, actionPoller & actionStatus. Just setting the expectation beforehand – It is not a post which will explain you all, but I will share the developer guide link for each of them so that you can go and read them (highly recommended).

actionRegion

The specifies the components to be processed on Force.com server. Without this tag, the whole page will be processed. With actionRegion also the whole form is submitted, but only the part within the tag will be processed.
It needs a reRender attribute to be effective. It will only refresh the part of the page using the data contained within the tag. This can be very effectively used to avoid validation errors that may occur due to present of standard validation rule in VF page like required attribute.
Here is the example without ActionRegion:
Controller:
public with sharing class WithoutActionRegionController {
public String valueEntered{get;set;}
public String country{get;set;}
public String state{get;set;}

public WithoutActionRegionController() {
country = '';
state = '';
valueEntered = '';
}

public PageReference countrySubmitted(){
valueEntered = 'Country: ' + country;
return null;
}
}
Visualforce Page:

<apex:page controller="WithoutActionRegionController">
<apex:form id="myForm">
<apex:pageMessages id="messages1"/>
<apex:pageBlock id="topPageBlock">
<apex:pageBlockSection columns="2" title="Country & State">
<apex:outputText value="Enter Country" />
<apex:inputText value="{!country}" >
<apex:actionSupport action="{!countrySubmitted}" reRender="messages1,outputId" event="onchange"/>
</apex:inputText>
<apex:outputText value="Enter State" />
<apex:inputText value="{!state}" required="true"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Output" id="outputId">
<apex:outputText value="{!valueEntered}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Output:

As you can see it throws the validation message due to state field is marked as required=true to moment I finish entering the country. This is because the whole page is submitted to render.

Now the same example with ActionRegion:

<apex:page controller="WithoutActionRegionController">
<apex:form id="myForm">
<apex:pageMessages id="messages1"/>
<apex:pageBlock id="topPageBlock">
<apex:pageBlockSection columns="2" title="Country & State">
<apex:outputText value="Enter Country" />
<apex:actionRegion>
<apex:inputText label="Enter Country" value="{!country}" >
<apex:actionSupport action="{!countrySubmitted}" reRender="messages1,outputId" event="onchange"/>
</apex:inputText>
</apex:actionRegion>
<apex:outputText value="Enter State" />
<apex:inputText value="{!state}" required="true"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Output" id="outputId">
<apex:outputText value="{!valueEntered}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Output:

This time no error message because actionRegion will render the Output and message1 part of the page with the content present inside tag. 

Reference: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_actionRegion.htm?search_text=actionregion

actionFunction

This allows calling controller functions directly from the JavaScript code using AJAX request. It is not the same as actionSupport which only allows calling controller functions from other Visualforce components. Few things to remember –

  • actionFunction is not allowed to be placed inside iteration component. It should be placed after the iteration component.
  • order is matched by the caller’s argument list. reRender attribute is needed to define
  • It doesn’t have event attribute. It doesn’t add Ajax request before calling the Controller method.
Example:
Controller:
public with sharing class ActionFunctionController {
public Boolean showHelloWorld{get;set;}
public String message {get;set;}
public ActionFunctionController(){
showHelloWorld = false;
message = '';
}

public PageReference shouldDisplayHelloWorld(){
showHelloWorld = true;
message = 'Now we can say Hello World';

return null;
}
}
Visualforce Page:
<apex:page controller="ActionFunctionController">
<apex:form>
<apex:actionFunction name="checkHelloWorldDisplay" action="{!shouldDisplayHelloWorld}" reRender="HelloWorldSection"/>
<apex:pageBlock>
<apex:pageBlockSection id="HelloWorldSection" columns="1">
<apex:inputCheckbox value="{!showHelloWorld}" onChange="checkHelloWorldDisplay()"/>
<apex:outputText value="{!message}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

</apex:page>

actionSupport

This can be used when we need the Visualforce component to be refreshed asynchronously by the server when a particular event occurs like button click or mouseover.
  • It adds the AJAX request to the Visualforce Page and then calls the controller function. This is how it different from actionFunction.
  • It also has event attribute. Another difference between actionFunction and actionSupport.
  • It can be placed inside an iteration component.

actionPoller

  • A timer that sends an AJAX request to server according to a time interval specified. Each request can result full or partial refresh of the page.
  • Enabled attribute is used to make poller as active or inactive. Default is active.
  • It won’t time out due to inactivity.