javasalesforceapexapex-codevisualforce

Using apex:repeat inside an apex:outputPanel


I have this VF that has a button inside the first outputPanel which acts like a gateway for the 2nd output panel to be shown

<apex:page standardController="SObject" contentType = "{!IF(!showForm, 'text/html', 'application/vnd.ms-excel#TestFile123.csv')}" showHeader="true" sidebar="true" extensions="Class123" lightningStylesheets="true">
    <apex:outputPanel layout="none" rendered="{!!showForm}"> <!-- Added Shifting VF Page | if showForm is FALSE-->
        <apex:form >
            <apex:commandButton action="{!activator}" value="Activator" id="xoxo"/>
        </apex:form>
    </apex:outputPanel>

    <apex:outputPanel layout="none" rendered="{!showForm}"> <!-- if showForm is TRUE-->
        {!header}
        <apex:repeat value="{!tXoxo}" var="TN" >
            {!TN.A},{!TN.B},{!TN.C},""
        </apex:repeat> 
    </apex:outputPanel>
</apex:page>

I'm able to have an extract of CSV file. However, the file only has the header / not showing any of the values of {!TN.A},{!TN.B},{!TN.C},"" which is inside the apex:repeat

THEN in the controller class:

//Constructor 2.0
    public Class123 (ApexPages.StandardController controller){    
    
        this.controller = controller;
        this.csSO = (SObject1)controller.getRecord();
        
        if(csSO != null){
                 csSO = [SELECT Id, 
                                H, 
                                c, N, 
                                D, E 
                            FROM SObject1 WHERE Id =: csSO.id];
            system.debug(csSO.Name);
            cTQwNs = [SELECT Id, 
                            A,
                            B,
                            C,
                            D
                        FROM SObject2 WHERE S =: csSO.id];
        }
    }

    public void activator() {//sets the showForm variable to true
        showForm = true;
        tXoxo = populateTestClass();
        system.debug(tXoxo[0]);
    }

Based on my debug logs, i can't seem to find the csSO.Name value. So im guessing "maybe controller is not passing anything at all?" Because after Classs123, there's this below it

public <dataType> populateTestClass() {}

which is what is being called by tXOxo and called inside the apex:repeat in the VF but it's not getting any value. My approach in passing the values inside the controller class is very direct so I can't find other possible cause of having null value being passed.

Anyone who has an idea if there really are instances wherein controller doesn't pass anything, and how to solve such issue??


Solution

  • Turns out it doesn't work if it's not the main controller. The class I was using as the 2ndary controller class was not working and therefore not setting any value at all -- therefore not able to pass any value.

    If you did what I did wherein I made another controller class, just make sure you're passing into it a different parameter. Cheers~~