[SalesForce] Sub Output Panel not rendering on Re-render

I am re-rendering a PageBlock ("DisplaySection") which contains a table which contains an OutputPanel. When I load "DisplaySection" directly from the controller, the OutputPanel renders as expected. When "DisplaySection" is rendered after clicking the CommandButton, the OutputPanel does not render, meaning the "subs1" records are not displayed.

The odd part is that when I remove the OutputPanel (despite setting rendered to "true" — done for testing), the "subs1" section displays as expected when rendered from the button refresh. Why does that OutputPanel not render when "DisplaySection" is not rendered from the initial page load?

I have stripped down the sample code but it contains all the structures as my real page.

The OutputPanel is set to rendered=true for testing purposes and to demostrate that it's not code in the controller that is messing anything up.

The "DisplaySection" renders properly in every case (initial page load and after the button is clicked) but the OutputPanel does not load/render after the button is clicked.

<apex:form id="MainForm">

    <apex:pageBlock id="MainSection">

        <apex:pageBlock id="InputSection" rendered="{!displayInputSection}">
            <apex:inputText value="{!recordId}"/> <br/>
            <apex:commandButton value="Inspect" action="{!inspectButton}" rerender="MainSection"/>
        </apex:pageBlock>

        <apex:pageBlock id="DisplaySection" rendered="{!displayDisplaySection}">

            <div>
            <table>
            <tr><th>--</th><th>--</th></tr>
            <apex:repeat value="{!fieldHolderList}" var="fh">

            <tr><td>{!fh.fn}</td><td>{!fh.ft}</td>

            <apex:repeat value="{!fh.subFields}" var="subs1">
                <apex:outputPanel rendered="true">
                <tr><td>({!subs1.fd})</td><td>{!subs1.fn}</td></tr>
                </apex:outputPanel>
               ....   

Best Answer

Rendered is not reevaluated when directly rerendering the element. You need to rerender the parent element.

If the element is not rendered initially a rerender on that element will not work

Since you are rerendering the MainForm the next possible check is to make sure that displayDisplaySection is updated to true in your controller on the button click

Since your apex code is not shown it is hard to tell but it is likely that the value is not updated to true

Update

Add layout=none to your outputpanel

The following is an example. Remove the layout=none to reproduce your issue, add it back to see it fixed

Page

<apex:page id="myExamplePage" controller="myExampleController">

    <apex:form>
        <apex:commandButton action="{!changeMe}" reRender="outside" value="Click me"/>
        <apex:outputpanel layout="block" id="outside">


            <table>
                <thead>
                <tr>
                    <th>Value</th>
                </tr>
                </thead>
                <tbody>
                <tr><td>MY VALUE</td></tr>

                <apex:repeat value="{!tmp}" var="v">
                    <apex:outputPanel layout="none" rendered="{!dorender}">
                    <tr><td>{!v}</td></tr>
                    </apex:outputPanel>
                </apex:repeat>

                </tbody>
            </table>

        </apex:outputpanel>

    </apex:form>


</apex:page>

Controller

public class myExampleController {

    public String[] tmp {get;set;}
    public boolean dorender {get;set;}
    public myExampleController(){
        tmp = New String[]{'A','B','C'};
        dorender = true;
    }

    public void changeMe(){
    tmp.add('D');
    }

}

There are some other issues with repeat and rerendering parent elements but that was not the case here