1

Well I am working on a visualforce page which has several sections with their own fields. The sections should be independent from each other. Now in one section I've got two operations: add and cancel. When I press the Add button I want that only the fields from its section are processed by the server.

However, when I press the Cancel button I don't need to process the section's field - just cancel. It means when cancelling I don't care if the required fields are populated. For this I am certainly need to cover the Cancel button within the apex:actionRegion element.

Here is a part of my code:

<apex:page>

    <apex:form id="recipients">

        <!-- other code is skipped for brevity -->

        <!-- New recepient section -->
        <apex:actionRegion>
            <apex:pageBlock id="addNewRecipient"
                            rendered="{! addNewRecipientVisible }">
                <apex:pageBlockButtons location="bottom">
                    <apex:commandButton value="Add"
                                        action="{! addRecipient }"
                                        reRender="recipients"/>

                    <apex:actionRegion>
                        <apex:commandButton value="Cancel"
                                            action="{! hideAddRecipient }"
                                            immediate="true"
                                            html-formnovalidate="formnovalidate"
                                            reRender="recipients"/>
                    </apex:actionRegion>
                </apex:pageBlockButtons>

                <apex:pageBlockSection columns="1"
                                       title="New recipient">

                    <apex:inputField id="recipientLanguage"
                                    value="{! recipient.Language__c }"/>

                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:actionRegion>

    </apex:form>

</apex:page>

Notice that there are 2 apex:actionRegion elements which are nested. I ran the code and it worked, but I would like to know if putting apex:actionRegion in another apex:actionRegion is a good practice and it does not have any implications.

3
  • Well, when I click on the Cancel button it hides the whole "addNewRecipient" page block. That's why I need rerender on the button.
    – Eduard
    Commented Nov 28, 2018 at 12:50
  • Thank you @SantanuBoral. That works for me - one actionRegion
    – Eduard
    Commented Nov 28, 2018 at 13:00
  • I have added as answer Commented Nov 28, 2018 at 13:12

1 Answer 1

3

I think cancel button within actionRegion is not needed if you don't need to process anything to the server and rerender specific portion. I would prefer not to use nested actionRegion.

Then outer actionRegion is fine for that, no need to use that for cancel.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .