Search Here

apex: actionRegion Component in Visualforce Page

 Another most important component that defines an area of the VF page. This area determines those components which we want to process by the Force.com server after generating an AJAX request.


The components inside the <apex: actionRegion> component are processed by the server, thereby increasing the page's performance. We use this method to get input from the user for the controller method that doesn't correspond to a field on a sObject field.


The <apex:actionRegion> component doesn't define the areas of the page that we want to re-render after completing the request. We use actionSupport, actionPoller, commandButton, commandLink, tab, or tabPanel components for controlling such behavior.


The <apex:actionRegion> component has the following attributes:


1. id

The id attribute is an identifier that allows the component to be referenced by other components on the page.


Syntax


<apex:actionRegion id= "regionId"></ apex:actionRegion>  

2. immediate

The immediate attribute is of type Boolean. If its value is true, the action associated with the component will happen immediately. The function will not process the validation rules associated with the fields on the page.


Syntax


<apex:actionRegion immediate= "true"></ apex:actionRegion>  

3. rendered

The rendered attribute is of type Boolean that is used for specifying whether this component is rendered on the page or not. By default, its value is set to true.


Syntax


<apex:actionRegion rendered= "true"></actionRegion>  

4. renderRegionOnly

The renderRegionOnly attribute is of type Boolean that is used for specifying whether AJAX-invoked behavior outside of the <apex:actionRegion> should be disabled when the <apex:actionRegion> component is processed if set to true.


Syntax


<apex:actionRegion renderRegionOnly= "true"></actionRegion>  

Let's take an example to understand how we can use the <apex:actionRegion> component in VF:


Note: In order to render the given example fully, we have to associate the page with a valid opportunity record in the URL.

ApexActionRegionExample.vfp


<!-- apex page with Lead standard controller-->  

<apex:page standardController = "Contact">  

    <!-- apex form start-->  

    <apex:form >  

        <!-- use pageBlock, pageBlockButtons, pageBlockSection, and pageBlockSectionItem-->  

        <apex:pageBlock title = "Edit Contact" id = "pb1" mode = "edit">  

            <!-- pageBlockButtons for adding Save and Cancel buttons-->  

            <apex:pageBlockButtons >  

                <apex:commandButton value = "Save" action = "{!save}"/>  

                <apex:commandButton value = "Cancel" action = "{!cancel}"/>  

            </apex:pageBlockButtons>  

              

            <!-- pageBlockSection for displaying FirstName, LastName, LeadSource and Email fields-->  

            <apex:pageBlockSection columns = "2">  

                <apex:inputField value = "{!contact.FirstName}"/>  

                <apex:inputField value = "{!contact.LastName}"/>  

                <!-- pageBlockSectionItem for displaying LeadSource field with support of actionRegion component-->  

                <apex:pageBlockSectionItem>  

                    <apex:outputLabel value = "{!$ObjectType.contact.fields.leadSource.label}"  

                                      for = "lead"/>  

                    <apex:actionRegion>  

                        <apex:inputField value = "{!contact.leadSource}" id = "lead">  

                            <apex:actionSupport event = "onchange" rerender = "pb1"  

                                                status = "status"/>  

                        </apex:inputField>  

                    </apex:actionRegion>  

                </apex:pageBlockSectionItem>  

                <apex:inputfield value = "{!contact.Email}"/>  

            </apex:pageBlockSection>  

            {!text(now())}  

        </apex:pageBlock>  

    </apex:form>  

</apex:page>  

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.