function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lakshmi SLakshmi S 

actionFunction and actionSupport functionality

Hi All,

Q). what is the difference between actionFunction and actionSupport, Explain with funcionality?

can anyone reply for this post...
Thanks in advance..
Best Answer chosen by Lakshmi S
swati_sehrawatswati_sehrawat
Hello,

Below links can help you to understand the concept for these two apex tags.

http://www.cloudforce4u.com/2013/06/difference-between-action-support-and.html
https://success.salesforce.com/answers?id=90630000000gzbQAAQ


Please mark this as solved, if it was able to solve your question.

All Answers

Rupal KumarRupal Kumar
Hi,
Difference between both:

1. Action function can call the controller method from java script.
2. Action support adds AJAX support to another visualforce component and then call the controller method. 
    for example:

  
<apex:outputpanel id="outptpnl">
             <apex:outputText value="click here"/>
         <apex:actionSupport event="onclick" action="{!controllerMethodName}"  rerender="pgblck" />
     </apex:outputpanel>


  
Here action support adds AJAX to output panel, so once you click on output panel controller method will be called.
  
3. Action function cannot add AJAX support to another component. But from a particular component which has AJAX support(onclick, onblur etc) action function can be called to call the controller method.
Example:
<apex:actionFunction name="myactionfun"  action="{!actionFunMethod}" reRender="outptText"/>
 <apex:inputcheckbox onclick="myactionfun" />

Thanks
Rupal kumar
 
swati_sehrawatswati_sehrawat
Hello,

Below links can help you to understand the concept for these two apex tags.

http://www.cloudforce4u.com/2013/06/difference-between-action-support-and.html
https://success.salesforce.com/answers?id=90630000000gzbQAAQ


Please mark this as solved, if it was able to solve your question.
This was selected as the best answer
Thota Rakesh 1Thota Rakesh 1
Hi Lakshmi Narasimha

Action function
1. Difference is in case of Action function we invoke AJAX using Java script while in case of Action support we may directly
invoke method from controller.
2. Actionfunction is a function that can be called by any component via onclick, ondbclick, onblur event of that component.

Example code:
 
<apex:page controller="exampleCon">
<apex:form>
<!-- Define the JavaScript function sayHello-->
<apex:actionFunction name="sayHello" action="{!sayHello}" rerender="out"
status="myStatus"/>
</apex:form>
<apex:outputPanel id="out">
<apex:outputText value="Hello "/>
<apex:actionStatus startText="requesting..." id="myStatus">
<apex:facet name="stop">{!username}</apex:facet>
</apex:actionStatus>
</apex:outputPanel>
<!-- Call the sayHello JavaScript function using a script element-->
<script>window.setTimeout(sayHello,2000)</script>
<p><apex:outputText value="Clicked? {!state}" id="showstate" /></p>
<!-- Add the onclick event listener to a panel. When clicked, the panel triggers
the methodOneInJavascript actionFunction with a param -->
<apex:outputPanel onclick="methodOneInJavascript('Yes!')" styleClass="btn">
Click Me
</apex:outputPanel>
<apex:form>
<apex:actionFunction action="{!methodOne}" name="methodOneInJavascript"
rerender="showstate">
<apex:param name="firstParam" assignTo="{!state}" value="" />
</apex:actionFunction>
</apex:form>
</apex:page>

Controller class:

public class exampleCon {
String uname;
public String getUsername() {
return uname;
}
public PageReference sayHello() {
uname = UserInfo.getName();
return null;
}
public void setState(String n) {
state = n;
}
public String getState() {
return state;
}
public PageReference methodOne() {
return null;
}
private String state = 'no';
}

ActionSupport
1. other difference is Action function may be commonly used from different place on page while action support may only be used for particular single apex component.

2. ActionSupport is added to a particular component like button or outputtext and the event is controlled by the actionsupport not the component thus actionsupport help enhance the compononment itself by being part of the component itself.


Example Code:
 
<apex:page controller="exampleCon">
<apex:form>
<apex:outputpanel id="counter">
<apex:outputText value="Click Me!: {!count}"/>
<apex:actionSupport event="onclick"
action="{!incrementCounter}"
rerender="counter" status="counterStatus"/>
</apex:outputpanel>
<apex:actionStatus id="counterStatus"
startText=" (incrementing...)"
stopText=" (done)"/>
</apex:form>
</apex:page>

Controller Class:

public class exampleCon {
Integer count = 0;
public PageReference incrementCounter() {
count++;
return null;
}
public Integer getCount() {
return count;
}
}


Kindly mark it as solved if it helps you.

Best Regards,
Rakesh.T




 
Amit Chaudhary 8Amit Chaudhary 8
1. difference is in case of Action function we invoke AJAX using Java script while in case of Action support we may directly
invoke method from controller
 
2. other difference is Action function may be commonly used from different place on page while action support may only be used for particular single apex component.

Please check below post for more detail and code
1) http://www.cloudforce4u.com/2013/06/difference-between-action-support-and.html
2) http://www.slideshare.net/AbdulMujebb/difference-betweenactionsupport
3) http://blog.biswajeetsamal.com/post/2015/10/09/difference-between-action-function-and-action-support/

Let us know if this will help you
swati_sehrawatswati_sehrawat
Hi Lakshmi,

If any of the answer was able to help you understand the concept, Can you please mark the thread as solved.