0

I have a custom controller to obtain a record set, which I invoke from a commandbutton. pbtable is a pageblocktable populated by the method searchproperties shown below.

 <apex:commandButton action="{!SearchProperties}" value="Search for Matching Properties" reRender="pbtable" />

Because it can take a bit of server time before returning a result set, I want to provide a message indicating the search has begun. Everything is nestled in pageblock and sections. Currently, I provide a message on the pageblocksection indicating both the length of time it took to produce the result set and how many records were found. So, ideally, upon clicking the commandbutton, I want to update the title to inform users the search has begun. Any ideas or different approaches are most appreciated. Thanks in advance.

 <apex:pageblocksection Columns="1" title="Step 3 - Select a property   {!ShowTotalMatches}" id="pbtable" />
  • 1
    You can use the status attribute on the commandButton for this, in conjunction with the apex:actionStatus element: developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/… – rael_kid Aug 3 '17 at 21:56
  • @rael_kid You should add this as an answer. – sfdcfox Aug 3 '17 at 23:42
  • Thank you! I'll check it out right now and let you know how I make out. – J.W. Aug 4 '17 at 0:37
  • Been playing around with it, and while I made progress, this is nothing more than a timer, which doesn't even fire off until at minimum 5 seconds later. Are there any other alternatives? – J.W. Aug 4 '17 at 4:07
0

You can use for providing message.

  <apex:commandButton action="{!SearchProperties}" value="Search for Matching Properties" reRender="pbtable" status="myStatus">

  <apex:actionStatus  id="myStatus" startText=" Loading..." stopText=""/>

  <apex:pageblocksection Columns="1" title="Step 3 - Select a property   {!ShowTotalMatches}" id="pbtable" >

Reference
Simple action status in Salesforce

apex:actionStatus

  • Fantastic! That's great and works well, but can I update the header in that pageblocksection? There's no status attribute available for a PBS so while I can output a status message, it won't be visible on the PBS header where I'd like it. – J.W. Aug 4 '17 at 16:07
  • if you want your PageBlockSection title to be dynamic , Then you have to create <apex:outputPanel > , give the id of the present pageblocksection to outputPanle. keep the pageblocksection inside outpupanel and render the outputPanel. something like this , <apex:outputPanel id="pbtable" > <apex:pageblocksection Columns="1" title="{! dynamicTitleForEachRender }" > //your content </apex:pageBlockSection> </apex:outputPanel> – NITHESH K Aug 7 '17 at 5:22
0

I usually have something like this on all my pages:

<apex:actionStatus id="loading" onstart="startLoading();" onstop="stopLoading();" />
    <div class="customLoader" id="customLoaderDiv"> 
        <div class="customLoaderContainer">
            <apex:image styleClass="loadingIcon" url="{!URLFOR($Resource.Bundle, 'img/loader.gif')}" />
        </div>
    </div>
</apex:actionStatus>

Along with these javascript functions:

$j(function() {
    $j('.customLoader').hide();
}

loadingCounter = 0;
function startLoading(){
    loadingCounter++; 
    $j('.customLoader').show(); 
}

function stopLoading(){
    if(--loadingCounter <= 0){ 
        $j('.customLoader').hide();
    }
}

If you add the status="loading" attribute on an apex:commandButton or apex:actionSupport or whatever supports it the function startLoading(); will be called and the loader will be shown. When the function completes stopLoading(); is called and the loader will be hidden. Usually I also add functionality to disable and re-enable buttons in the functions, but you could do whatever you need. This

  • I like this, however it appears on the initial page load showing the action status, yet with the first and subsequent clicks, it works perfectly. How do you initialize it? – J.W. Aug 4 '17 at 13:49
  • Ah, yes, there's a tiny piece of Javascript for that. I've added it to my answer. – rael_kid Aug 7 '17 at 8:57

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.