3

I have a pretty batch that is trigger from a VF page. Then I check the batch status using an ActionPoller until it is completed and finally I rerender the batch results.

Everything is working fine but the pageMessages rerender. I can't figure out why.

I could check that the msgPanel is rerendering ok using the NOW. But the ApexPage.Messages is empty.

My VF looks like this:

<apex:outputPanel id="msgPanel">
      <h1>{!NOW()}</h1> 
      <apex:pageMessages id="msg"/>
 </apex:outputPanel>

 <apex:actionPoller interval="5" action="{!checkBatchStatus}" enabled="{!batchStatus}" onsubmit="console.log('checking..');" oncomplete="{!batchComplete}&&refreshJS();" />

<apex:actionFunction action="{!refreshGenerate}" name="refreshJS" reRender="msgPanel,resultsPanel" /> 

In the controller I have this:

public PageReference checkBatchStatus(){

            AsyncApexJob job    =   [select........1];
        if(job.Status == 'Completed'){

            ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.CONFIRM ,
             currentBatch+' Completed. '));
            //some internal checks
            if(errors){
                    ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR ,errorDescription);
            }

            batchComplete = true;
            batchStatus = false;
        }else{


         batchStatus = true;
             }
  return null;
    }
   public void refreshGenerate(){ 
      // empty method, it is just used by javascript to trigger some rerenders.
    }

Is this a rerender bug of salesforce ?

Please help

6
  • What does the refreshGenerate apex function do? Can't you just put the rerender attribute on the actionPoller instead of the actionFunction? Sep 13, 2014 at 20:27
  • refreshGenerate do nothing, Im using it as a javascript helper to handle the rerender from javascript, I can't use the rerender on the actionPoller because it is called each time the poller is executed and I only need to rerender when the poller check that the batch has completed.
    – jm-cloud
    Sep 13, 2014 at 22:48
  • In this case I would just put the rerender on the actionPoller. The AJAX call will be done anyway, I don't expect the rerender to affect the performance. Have you tried it? Sep 14, 2014 at 8:25
  • 2
    And what happens if you only rerender the msgPanel from the actionPoller? Sep 14, 2014 at 8:39
  • 2
    Amazing, it worked. It seams like actionPoller onComplete event is doing something weird in the stateview, cleaning the ApexPage.message. I think that the lack of performance is not an issue. Post your answer. I'll be glad to accept it.
    – jm-cloud
    Sep 14, 2014 at 9:26

1 Answer 1

1

It seems that the pageMessages behave a bit like a transient variable. Since you rerender the pageMessages element in another request (the actionFunction, rather than the actionPoller), the values are resetted. I haven't confirmed this yet.

If you move the rerender of the pageMessages element as a part of the actionPoller it will work.

You must log in to answer this question.

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