[SalesForce] CommandButton reRender causing action to fire twice

I havea custom save button on a visualforce page as below. I wanted to use actionstatus to show the user that the save process was taking place/in progress. However recently the redirect stopped for me, then looking at the debug logs I noticed the {!onSave} action was taking place twice.

            <apex:actionStatus id="saveCart">
                <apex:facet name="stop">
                    <apex:commandButton action="{!onSave}" value="Save" status="saveCart" reRender="msgs"/>
                </apex:facet>

                <apex:facet name="start">
                    <apex:outputPanel >
                        <apex:image value="/img/loading32.gif" style="height: 15px"/>
                        <apex:commandButton value="Saving..." status="saveCart" disabled="true"/>
                    </apex:outputPanel>
                </apex:facet>                       
            </apex:actionStatus>

The onSave action as defined in my extension is:

public PageReference onSave(){

if(forDeletion.size()>0)
    try{
        delete(forDeletion);
    }
    catch(Exception e){
        ApexPages.addMessages(e);
        return null;                
    }

try{
    if(shoppingCart.size()>0)
        upsert(shoppingCart);
}
catch(Exception e){
    ApexPages.addMessages(e);
    return null;
    }  // to allow formatting of lost lines

return new PageReference('/' + ApexPages.currentPage().getParameters().get('Id'));
}

I've removed the action status and stripped the save button down to the below, and this works – the {!onSave} action only gets called once and the page redirects. But as soon as I add a reRender parameter it fails to redirect again…what could cause this? And how can I get the actionstatus back in?

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

I've ruled out the browser (same behavior occurred on IE, FF and Chrome) and tried on a different instance (CS8 and CS14).

Best Answer

Sounds similar to an issue I faced - there are a couple of answers worth trying, but I think it is using the status with a PageBlockButton that seems to cause the issue...if you take it out of the pageblock markup, does it still fire twice?

Related Topic