Activity › Forums › Salesforce® Discussions › What is the use of actionfunction ?
-
What is the use of actionfunction ?
Posted by Saddam on September 3, 2019 at 11:31 AMWhat is the use of actionfunction ?
Achintya replied 6 years, 8 months ago 3 Members · 2 Replies -
2 Replies
-
This tag defines JavaScript functions to be called from JavaScript code. By using this tag you can call controllers methods from java script code using an AJAX request .
This component must be a child of <apex:form> tag. And we cannot place this tag inside an iteration tag like <apex:pageBlockTable> & <apex:repet> now. Earlier we were able to do this.But with api version 23 we cannot place <apex:actionFunction> inside iteration tags
- [adinserter block='9']
-
A component that provides support for invoking controller action methods directly from JavaScript code using an AJAX request. An <apex:actionFunction> component must be a child of an <apex:form> component.
<apex:page controller="exampleCon"> <apex:outputPanel onclick="methodOneInJavascript('Yes!')" styleClass="btn"> </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>In the above visualforce page javascript method in the on-click event will call the apex controller method with the help of actionfunction.
Apex controller. With the help of actionfunction we can able to make a call to the apex 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'; }
Log In to reply.