0

I have a visualforce page that calls a custom component. Both the VF page and the custom component have apex:pageMessages tags embedded in them. I put a wrapper class around the apex:pageMessages so that I can specify which messages I want displayed via the rerender attribute on a command button.

Here is some pseudo-code to help describe my situation...

VF page

<apex:page controller="ChooseContactController">
//JS-CSS includes
<apex:form >
    <apex:pageBlock title="Choose a contact" mode="edit">
        <apex:pageBlockButtons >
            <input type="button" class="btn show-modal" value="New Contact"/>
            <apex:commandButton action="{!save}" value="Save" rerender="chooseContactPageMessagesWrapper"/>
        </apex:pageBlockButtons>
        <apex:outputPanel id="chooseContactPageMessagesWrapper">
            <apex:pageMessages />
        </apex:outputPanel>
        //Data
    </apex:pageBlock>
</apex:form>

<div id="modal-div" title="Create Contact" style="display:none;">
    <c:CreateContact theAccountId="{!accountId}" />
</div>

CreateContact Component

<apex:component controller="CreateContactComponent" selfClosing="true" allowDML="true">
<apex:attribute name="theAccountId" description="The account Id the contact belongs to" type="Id" assignTo="{!accountId}" required="true" />
<apex:form >
    <apex:pageBlock title="Create a new contact">
        <apex:outputPanel id="createContactPageMessagesWrapper">
            <apex:pageMessages />
        </apex:outputPanel>
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save" rerender="createContactPageMessagesWrapper"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
</apex:form>

When a user tries to create a new contact within the custom component, I want any error to be displayed in the component's pageMessages and not refresh the page. However, if the save action is successful, I want the entire page to be refreshed.

Is there a way to refresh a page in a command button's action method, or in a javascript method after the action is complete, that has the rerender attribute defined?

3

If you do not provide the rerender attribute on the commandbutton then the whole page will refresh.

You can also provide multiple ids in your rerender attribute separated by commas (,). So with that you can refresh different sections of the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.