actionfunction component provides support for invoking controller action methods directly from JavaScript code using an AJAX request.
It is different from actionsupport which only provides support for invoking controller action methods from other Visualforce components, actionfunction defines a new JavaScript function which can then be called from JavaScript code.
In the example below, we are showing one picklist with name customer priority. Whenever we will change customer, then javascript method will be called. And we have specified corresponding controller action method in actionfunction component method. In controller method we are checking if customer priority is high then we are setting boolean variable as true. So phone textbox will be rendered automatically without refreshing full page
Visualforce Code:
<apex:page controller="actionFunctionController" tabStyle="Account"> <apex:form > <apex:actionFunction name="priorityChangedJavaScript" action="{!priorityChanged}" rerender="out"/> <apex:pageBlock > <apex:pageBlockSection title="If you will select High Customer Priority then phone textbox will be shown" columns="1" id="out" collapsible="false"> <apex:inputField value="{!acc.CustomerPriority__c}" onchange="priorityChangedJavaScript()"/> <apex:inputField value="{!acc.Phone}" rendered="{!showPhone}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Apex Code:
public class actionFunctionController { public Account acc{get;set;} public Boolean showPhone{get;set;}
public actionFunctionController(){ acc = new Account(); showPhone = false; }
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 a 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 the 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 controller's 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.
Visuaforce 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"/> </apex:outputpanel>
<apex:outputpanel id="panel2"> <apex:outputText value="Click here to decrement!"/> <apex:actionSupport event="onclick" action="{!decrementCounter}" rerender="out"/> </apex:outputpanel>
actionfunction component provides support for invoking controller action methods directly from JavaScript code using an AJAX request.
It is different from actionsupport which only provides support for invoking controller action methods from other Visualforce components, actionfunction defines a new JavaScript function which can then be called from JavaScript code.
In the example below, we are showing one picklist with name customer priority. Whenever we will change customer, then javascript method will be called. And we have specified corresponding controller action method in actionfunction component method. In controller method we are checking if customer priority is high then we are setting boolean variable as true. So phone textbox will be rendered automatically without refreshing full page
Visualforce Code:
<apex:page controller="actionFunctionController" tabStyle="Account"> <apex:form > <apex:actionFunction name="priorityChangedJavaScript" action="{!priorityChanged}" rerender="out"/> <apex:pageBlock > <apex:pageBlockSection title="If you will select High Customer Priority then phone textbox will be shown" columns="1" id="out" collapsible="false"> <apex:inputField value="{!acc.CustomerPriority__c}" onchange="priorityChangedJavaScript()"/> <apex:inputField value="{!acc.Phone}" rendered="{!showPhone}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Apex Code:
public class actionFunctionController { public Account acc{get;set;} public Boolean showPhone{get;set;}
public actionFunctionController(){ acc = new Account(); showPhone = false; }
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 a 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 the 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 controller's 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.
Visuaforce 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"/> </apex:outputpanel>
<apex:outputpanel id="panel2"> <apex:outputText value="Click here to decrement!"/> <apex:actionSupport event="onclick" action="{!decrementCounter}" rerender="out"/> </apex:outputpanel>
Action Function
actionfunction component provides support for invoking controller action methods directly from JavaScript code using an AJAX request.
It is different from actionsupport which only provides support for invoking controller action methods from other Visualforce components, actionfunction defines a new JavaScript function which can then be called from JavaScript code.
In the example below, we are showing one picklist with name customer priority. Whenever we will change customer, then javascript method will be called. And we have specified corresponding controller action method in actionfunction component method. In controller method we are checking if customer priority is high then we are setting boolean variable as true. So phone textbox will be rendered automatically without refreshing full page
Visualforce Code:
<apex:page controller="actionFunctionController" tabStyle="Account">
<apex:form >
<apex:actionFunction name="priorityChangedJavaScript" action="{!priorityChanged}" rerender="out"/>
<apex:pageBlock >
<apex:pageBlockSection title="If you will select High Customer Priority then phone textbox will be shown" columns="1" id="out" collapsible="false">
<apex:inputField value="{!acc.CustomerPriority__c}" onchange="priorityChangedJavaScript()"/>
<apex:inputField value="{!acc.Phone}" rendered="{!showPhone}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Code:
public class actionFunctionController {
public Account acc{get;set;}
public Boolean showPhone{get;set;}
public actionFunctionController(){
acc = new Account();
showPhone = false;
}
public PageReference priorityChanged(){
if(acc.CustomerPriority__c == 'High'){
showPhone = true;
}
else{
showPhone = false;
}
return null;
}
}
Action Support
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 a 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 the 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 controller's 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.
Visuaforce 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"/>
</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>
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;
}
}
Thank You
Ajay Dubedi
All Answers
Please go through the following link and hope it will help you to understand the actual difference.
http://www.cloudforce4u.com/2013/06/difference-between-action-support-and.html
Please mark as best answer if the above helps..!!!
Action Function
actionfunction component provides support for invoking controller action methods directly from JavaScript code using an AJAX request.
It is different from actionsupport which only provides support for invoking controller action methods from other Visualforce components, actionfunction defines a new JavaScript function which can then be called from JavaScript code.
In the example below, we are showing one picklist with name customer priority. Whenever we will change customer, then javascript method will be called. And we have specified corresponding controller action method in actionfunction component method. In controller method we are checking if customer priority is high then we are setting boolean variable as true. So phone textbox will be rendered automatically without refreshing full page
Visualforce Code:
<apex:page controller="actionFunctionController" tabStyle="Account">
<apex:form >
<apex:actionFunction name="priorityChangedJavaScript" action="{!priorityChanged}" rerender="out"/>
<apex:pageBlock >
<apex:pageBlockSection title="If you will select High Customer Priority then phone textbox will be shown" columns="1" id="out" collapsible="false">
<apex:inputField value="{!acc.CustomerPriority__c}" onchange="priorityChangedJavaScript()"/>
<apex:inputField value="{!acc.Phone}" rendered="{!showPhone}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Code:
public class actionFunctionController {
public Account acc{get;set;}
public Boolean showPhone{get;set;}
public actionFunctionController(){
acc = new Account();
showPhone = false;
}
public PageReference priorityChanged(){
if(acc.CustomerPriority__c == 'High'){
showPhone = true;
}
else{
showPhone = false;
}
return null;
}
}
Action Support
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 a 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 the 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 controller's 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.
Visuaforce 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"/>
</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>
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;
}
}
Thank You
Ajay Dubedi
Here is good explanation as well,
https://www.sfdc-lightning.com/2018/09/action-function-in-salesforce.html
https://www.sfdc-lightning.com/2018/09/action-support-in-salesforce.html