function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Maggie LongshoreMaggie Longshore 

How do I hide a component on some layouts but still perform work?

I have a component that we only show on some layouts for an object.  It has a polling function that monitors changes to the object (an object from a managed package). One function of the polling is to refresh the page when some custom field values change.

I need this refresh functionality now on all layouts for this object, but I do not want to display anything on the actual page in the layouts that do not need it.

What I have tried is to put a public boolean on the controller that says whether or not to render the controls. What this does is hide the controls but leaves a large white space on the page where the controls would be. Of course I do not want this space to show.

Here is a simplified version of my page :
 
<apex:component controller="CustomQuoteMetrics" allowDML="true" >
    <apex:form id="customQuoteMetrics">
        <apex:actionPoller action="{!queryQuote}"  rerender="metrics"  interval="90" />
        <apex:outputPanel rendered="{!refreshQuoteNow}">
        <script>
              window.top.location='/{!quoteID}';
        </script>
        </apex:outputPanel>
        <apex:pageBlock id="metrics" rendered="{!showCustomComponent}">
        </apex:pageBlock>
    </apex:form>
</apex:component>

Any ideas on what I could do differently?
I am a (c#, c++, JavaScript...) developer, but have only been writing apex code on the salesforce platform for about 8 months, so I realize I may not be headed in the right direction.
Phillip SouthernPhillip Southern
HI Maggie, have you tried:

1.) using the showCustomComponent in the rendered tag for apex:component
or 
2.) still use your pageblock but set everything else inside it (form, actionpoller, etc) To where pageblock is a direct child element of the component.

 
Maggie LongshoreMaggie Longshore
I have tried everything in one block. Will the actionpoller run if the block it is contained in is not rendered? I had difficulty with this.

Another way I could do it is to split this into 2 components - is there a way to have a component take 0 space?