What is action methods ?
After the page load, we can send requests to server asynchronously to perform some actions which is called action methods. This is achieved by sending POST request along with necessary parameters in headers.
When it will be useful ?
This is useful in cases where user needs to take small actions & update the small portion of the screen without reloading the whole page.How to pass values to action methods ?
We can pass parameters using param tag for these four action tags,- apex:commandButton
- apex:commandLink
- apex:actionSupport
- apex:actionFunction
Where is the code ?
Here's the illustration for passing parameters for these four different action methods,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page controller="testcls3_06122016"> | |
<apex:form> | |
<apex:actionFunction name="actionFn_Js" reRender="UserMessage"> | |
<apex:param name="actionName" value="Link-ActionFunction" assignTo="{!actionName}"/> | |
</apex:actionFunction> | |
<apex:panelGrid columns="2"> | |
<!-- commandbutton --> | |
<apex:outputText value="CommandButton"/> | |
<apex:commandButton value="Click me" reRender="UserMessage"> | |
<apex:param name="actionName" value="CommandButton" assignTo="{!actionName}"/> | |
</apex:commandButton> | |
<!-- commandlink --> | |
<apex:outputText value="CommandLink"/> | |
<apex:commandLink value="Click me" reRender="UserMessage"> | |
<apex:param name="actionName" value="CommandLink" assignTo="{!actionName}"/> | |
</apex:commandLink> | |
<!-- actionsupport --> | |
<apex:outputText value="ActionSupport"/> | |
<apex:selectList size="1"> | |
<apex:actionSupport event="onchange" reRender="UserMessage" > | |
<apex:param name="actionName" value="SelectList-ActionSupport" assignTo="{!actionName}"/> | |
</apex:actionSupport> | |
<apex:selectOption itemValue="Option1" itemLabel="Option1" /> | |
<apex:selectOption itemValue="Option2" itemLabel="Option2" /> | |
</apex:selectList> | |
<!-- actionfunction --> | |
<apex:outputText value="ActionFunction"/> | |
<apex:outputLink onclick="actionFn_Js('Link-ActionFunction');return false;"> | |
Click me | |
</apex:outputLink> | |
<!-- User Output Message --> | |
<apex:outputPanel id="UserMessage"> | |
<apex:outputText value="User Message" rendered="{!actionName != Null}"/> | |
<apex:outputText rendered="{!actionName != Null}"> | |
User clicked this action - {!actionName} | |
</apex:outputText> | |
</apex:outputPanel> | |
</apex:panelGrid> | |
</apex:form> | |
</apex:page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class testcls3_06122016 { | |
public String actionName{get;set;} | |
} |
hi ,
ReplyDeleteyour blog is very useful to me thank you
Nice blog man, thanks so much!
ReplyDeleteThanks
ReplyDelete