Visualforce Action Region <apex:actionRegion> Example.
Hi,
In this post i am giving an example of <apex:actionRegion> usage in visualforce. it will use to achieve AJAX functionality to partial page refresh.
Controller Class:
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;
}
}
}
}
Visualforce Page :
<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>
Output :
once you enter account number value in Account Number text box and click on Retrive button it going to get the details of "Account Name", "Account Type" with out reloading entire page.using action region we are updating particular HTML area section with Rerender Tag.