0

I have a problem with VF Page and its controller. I want to render the pageBlock and its link ( tag) under that only when batchComplete = true. In my case, it's getting displayed irrespective of whether batchComplete values is true or false.

Apex class:

public class PrepareDownloadController {
    public Boolean batchComplete { public get; private set; }
    public Boolean attachmentsComplete {public get; public set;}
    public string urlToZip {public get; public set;}

    public PageReference checkProgress() {
        if (totalAttachments == processedAttachments) {
            batchComplete = true;

            // if there are some error messages do not continue, so the user can see the errors
            if (!ApexPages.hasMessages(ApexPages.Severity.ERROR) && !debug) {
                final PageReference next = new PageReference(url);
                return next;
            }
        }
        final AsyncApexJob a = [
            SELECT Id, Status, ExtendedStatus, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email
            FROM AsyncApexJob
            WHERE Id = :createBatchId
        ];
        totalAttachments = a.TotalJobItems;
        processedAttachments = a.JobItemsProcessed;
    }
}

VF-Page:

<apex:outputPanel id="progress" layout="block">
        <apex:actionPoller action="{!checkProgress}" reRender="messages, progress, debug" interval="5" enabled="{!batchComplete}"/>
    </apex:outputPanel>
    <apex:outputPanel rendered="{!batchComplete != null, false,true)}" id="zipFiles">
        <p>
           {!batchComplete}
        </p>
    </apex:outputPanel>

I have truncated the code(attached only a part of it) and variables for brevity as the issue is with only batchComplete variable.

1 Answer 1

2

You seem to have true and false backwards. The poller will never be enabled, because the default value is null, which is considered false. Further, the default value is null, so the render property will always be true, with no way to update. In addition, you're not reRendering the zipFiles section. Note that it's probably a bad idea to leave batchComplete as null, because that makes the syntax unnecessarily awkward.

First, add this to your Apex:

public PrepareDownloadController() {
  batchComplete = false;
}

Then, change your Visualforce as follows:

<apex:outputPanel id="progress" layout="block">
    <apex:actionPoller action="{!checkProgress}" reRender="messages,progress,debug,zipFiles" interval="5" enabled="{!not(batchComplete)}"/>
</apex:outputPanel>
<apex:outputPanel rendered="{!batchComplete}" id="zipFiles">
    <p>
       {!batchComplete}
    </p>
</apex:outputPanel>

You must log in to answer this question.

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