Wednesday, 22 August 2018

Action tags in salesforce

Action tags support for calling action and refresh the field only not visualforce page.

Action Function :
===================
Action Function is used in the visualforce page to call the service side method using javascript and does not add the Ajax Request before calling the Controller method.

ex :
<apex:actionFunction name=”myactionfun”
action=”{!actionFunctionTest}”
reRender=”pgBlock, pbSection” />

Action Support :
================
As the name indicates action support is used to provide the support to the input field where we can not get event either manually or external event.It adds the AJAX request to visualforce Page and then calls the controller method.

<apex:inputText value=”{!dummyString}” >
                      <apex:actionSupport event=”onchange” action=”{!actionSupportTest}”                                     reRender=”pgBlock, pbSection” />
</apex:inputText>

Action Poller :
================
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:actionPoller action=”{!incrementCounter}” reRender=”counter” interval=”15″ enabled = “true” />

Action Region :
===============
Action Region use AJAX functionality to update partial page.

ex :

<apex:page controller="ActionRegionCLS" >
 <apex:pagemessages id="msgs"></apex:pagemessages>
 <apex:form >
  <apex:pageblock id="pb">
   <table>
     <apex:actionRegion >
      <tr>
        <td> <apex:outputLabel value="Enter Account Number"> </apex:outputLabel> </td>
        <td>             
          <apex:inputtext value="{!reqAccNumber}"/>
          <apex:commandButton value="Retrive" action="{!fillRecord}" rerender="pb,msgs"/>
          </td>
       </tr> 
     </apex:actionRegion>
     <tr>
      <td> <apex:outputLabel value="Account Name"> </apex:outputLabel> </td>
      <td>
        <apex:inputField value="{!accObj.Name}"/>
      </td>
     </tr>
     <tr>
     <td> <apex:outputLabel value="Account Type"> </apex:outputLabel> </td>
      <td>  <apex:inputField value="{!accObj.Type}"/> </td>
     </tr>
   </table>
  </apex:pageblock>
 </apex:form>
</apex:page>

public class ActionRegionCLS{
 public String reqAccNumber{get;set;}
 public Account accObj{get;set;}

 public ActionRegionCLS(){
  accObj = new Account();
 }
 public void fillRecord(){
  if(reqAccNumber !=null && reqAccNumber !=''){
    List<Account> accLst = new List<Account>();
    accLst = [select id,Name,AccountNumber,Type,AnnualRevenue from Account where AccountNumber =:reqAccNumber];
    if(accLst !=null && accLst.size()>0){
     accObj = accLst[0];
    }
    else{
 
     ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Info,' No Records found with this Account Number:'+reqAccNumber);
     ApexPages.addMessage(myMsg);
     accObj  = null;
 
    }
  }
 }

 }

Action status :
===============

A component that displays the status of an AJAX update request.An AJAX request can
either be in progress or complete.

ex :

<apex:actionStatus id="statusSaveTrip" stopText="">
    <apex:facet name="start">
        <div>
            <div class="popupBackground" />
            <div class="PopupPanel">
                <table border="0" width="100%" height="100%">
                    <tr>
                        <td align="center"><b>Please Wait</b></td>
                    </tr>
                    <tr>
                        <td align="center"><img src="{!$Resource.AJAXProgressBar}"/></td>
                    </tr>
                </table>
            </div>
        </div>
    </apex:facet>
</apex:actionStatus>

Note :

1.actionStatus: used to display start and stop statuses of AJAX requests.
2.actionSupport: used to call a second component when an event happens to the first component.
3.actionPoller: similar to actionSupport, but the event is based on a timer instead of a user action.
4.actionFunction: provides support for invoking a controller action from JavaScript code using an AJAX request by defining a new JavaScript function.
5.actionRegion: used to demarcate which parts of the page the server should reprocess.

No comments:

Post a Comment