1.apex:actionFunction
2.apex:actionPoller
3.apex:actionRegion
4.apex:actionStatus
5.apex:actionSupport
ActionRegion :
ActionRegion tells to Force.com server which components shoud be processed.
Whatever inside an ActionRegion is processed by a server when AJAX request is generated
on event such as "KeyPress" or "onClick" etc.
Note :
Sigifies which components should be processed by the server when an AJAX request is generated.
ActionRegion defines the source components that needs to be processed at the server end when the request is sent.
(or)
ActionRegion tag defines which componnets of VF page should be processed by Force.com server.
By Components means, all the visualforce tags like inputField, inputText, outputPanels etc.
ex :
<apex:pageBlock title="Page block" mode="edit" id="infoblock">
<apex:pageBlockSection title="Information" columns="1">
<apex:actionRegion>
<apex:inputField value="{!myCustomObject.Opportunity__c}">
<apex:actionSupport event="onchange" action="{!changeOpportunity}" rerender="additionalinfo"/>
</apex:inputField>
</apex:actionRegion>
<apex:inputField value="{!myCustomObject.MyRequiredField__c}" required="true" />
</apex:pageBlockSection>
<apex:pageBlockSection title="Additional Info" columns="1" id="additionalinfo">
<apex:inputField value="{!myCustomObject.Field1__c}" />
<apex:inputField value="{!myCustomObject.Field3__c}" />
<apex:inputField value="{!myCustomObject.Field3__c}" />
<apex:inputField value="{!myCustomObject.Field4__c}" />
</apex:pageBlockSection>
</apex:pageBlock>
ActionSupport :
ActionSupport adds AJAX support to another component, allowing the component to be refreshed asynchronously by the server
when a particular event occurs, such as a button click or mouseover.
ex 1:
Used when we want to perform an action on a perticular eventof any control like onchange of any text box or picklist.
<apex:inputText value="{!dummyString}" >
<apex:actionSupport event="onchange" action="{!actionSupportTest}" reRender="pgBlock, pbSection" />
</apex:inputText>
ex 2 :
<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>
public class exampleCon {
Integer count = 0;
public PageReference incrementCounter() {
count++;
return null;
}
public Integer getCount() {
return count;
}
}
ActionStatus :
ActionStatus is usually used to show the status of an AJAX Process to which it is related to.
ex:
ActionStatus showing text during the update the page and showing a loading gif.
<apex:page controller="AccountFiltctr">
<apex:actionStatus id="ProgStatusId" rendered="{!actionstatusrendered}">
<apex:facet name="start">
<div class="waitingSearchDiv" id="el_loading" style="background-color: #fbfbfb;height: 100%;opacity:0.65;width:100%;">
<div class="waitingHolder" style="top: 74.2px; width: 91px;">
<img class="waitingImage" src="/img/loading.gif" title="Please Wait..." />
<span class="waitingDescription">Please Wait...</span>
</div>
</div>
</apex:facet>
</apex:actionStatus>
<apex:form id="frm">
<apex:commandButton value="Test" status="ProgStatusId" reRender="pb1"/>
</apex:form>
</apex:page>
ActionFunction :
ActionFunction is a component, which provides support for invoking controller action
methods directly from javascript code with the use of AJAX request.
ex :
<apex:page controller="MyController">
<apex:form >
<apex:actionFunction name="getAccountMappedFunction" action="{!getAccount}" oncomplete="doOnComplete('{!MyAccount.Name}');">
<apex:param name="accountName" value="GenePoint"/>
</apex:actionFunction>
</apex:form>
<script >
getAccountMappedFunction();
function doOnComplete(name)
{
alert(name);
}
</script >
</apex:page>
public with sharing class MyController
{
public Account MyAccount {get; set;}
public PageReference getAccount()
{
String accountName = Apexpages.currentPage().getParameters().get('accountName');
MyAccount = [SELECT Name FROM Account WHERE Name = :accountName];
return null;
}
}
Note :
Allows for controller methods to be called directly from javascript.
Must be encapsulated in <apex:form> tags.
ActionPoller :
ActionPoller sends the AJAX request to the server periodically according to specified time interval.
Note :
A timer that sends an AJAX request to the server according to a time interval that you specify.
Each request can result in a full or partial page update.
ex :
<apex:page controller="exampleCon" sidebar="false">
<apex:form >
<apex:outputText value="Watch the changing fruit: {!count} : {!currentFruit}" id="counter"/>
<apex:actionPoller action="{!incrementCounter}" reRender="counter" interval="6"/>
</apex:form>
</apex:page>
public class exampleCon {
private List<String> fruitList = new List<String>();
Integer count = 0;
// Fruit name to be displayed
public String currentFruit {
get{
currentFruit = fruitList[count];
return currentFruit;
}
set;
}
// Increment the counter value
public PageReference incrementCounter() {
if(count< 6) {
count++;
} else {
count = 0;
}
return null;
}
public Integer getCount() {
return count;
}
// Constructor define the list of fruits
public exampleCon () {
fruitList.add('Mango');
fruitList.add('Apple');
fruitList.add('Pineapple');
fruitList.add('Banana');
fruitList.add('Orange');
fruitList.add('Grape');
fruitList.add('Peach');
}
}
No comments:
Post a Comment