0

It appears I have something wrong in my syntax for the output panels but I can't figure out what it is. Can someone tell me what I am doing wrong? The page doesn't rerender when I click the account name.

The problem code starts at ActionSupport.

    <apex:page controller="LicensingGridController" sidebar="false">

    <apex:pageBlock >
        <apex:pageBlockTable value="{!TheHubs}" var="Hub">
            <apex:column value="{!Hub.Name}" />
            <apex:column >
                <apex:facet name="header">Licenses</apex:facet>
                <ul>
                    <apex:repeat value="{!Hub.Licenses__r}" var="Lic">
                        <li><apex:outputField value="{!Lic.Name}" /></li>
                    </apex:repeat>
                </ul>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Accounts</apex:facet>
                <ul>
                    <apex:repeat value="{!Hub.Account_Counselors__r}" var="Counselor">
                        <apex:outputpanel id="Accounts">
                            <li><apex:outputLabel value="{!Counselor.Account__r.Name}" / ></li>
                                <apex:actionSupport event="onclick" action="{!fetchOEs}" rerender="pbOEs">
                                    <apex:param name="SelectedAcc" assignTo="{!SelectedAccid}" value="{!Counselor.Account__c}"/>
                                    <apex:param name="AccRendered" assignTo="{!AccRendered}" value="TRUE"/>
                                </apex:actionSupport>
                            </apex:outputPanel>

                    </apex:repeat>

                </ul>
            </apex:column>
            <apex:column headerValue="OE Dates">
                 <apex:outputpanel id="pbOEs" >
                    <apex:repeat value="{!OpenEnrollments}" var="OE" rendered="{!AccRendered}">
                        <apex:outputField value="{!OE.Start_Date__c}"/>
                    </apex:repeat>
                 </apex:outputpanel>
            </apex:column>

        </apex:pageBlockTable>

    </apex:pageBlock>

</apex:page>

Here is my controller code if needed for reference:

 public class LicensingGridController {

    public String selectedAccId {get; set;}
    public Boolean AccRendered {get; set;}

    public LicensingGridController(){
        AccRendered = FALSE;
    }
    //
    public List<BCS__c> getTheHubs() {
        List<BCS__c> hubs = [Select Id, Name, User__r.Name,
                             (Select Id,Account__c,Account__r.Name,Hub_Name__r.Name
                              FROM Account_Counselors__r),
                             (Select Name 
                              FROM Licenses__r)
                             FROM BCS__c
                             WHERE Inactive__C = FALSE];
        return hubs;
    }

    public list<OE_Rollover_Spans__c> getOpenEnrollments(){
        AccRendered = TRUE;
        List<OE_Rollover_Spans__c> OEs = [Select Account__c,Name,OE_Type__c,Start_Date__c,End_Date__c
                                          FROM OE_Rollover_Spans__c];
        return OEs;
    }

    public list<OE_Rollover_Spans__c> fetchOEs(){
        AccRendered = TRUE;
        List<OE_Rollover_Spans__c> OEs = [Select Account__c,Name,OE_Type__c,Start_Date__c,End_Date__c
                                          FROM OE_Rollover_Spans__c
                                          WHERE Account__c = :selectedAccId];
        return OEs;
    }

}

Bonus points: I can't get the fetchOEs to work in the apex:repeat for the second output panel called pbOEs. Can anyone tell me the correct syntax?

8
  • 1
    can you make the "AccRendered" true in the "fetchOEs()" method. When you rerender the outputpanel with id="pbOEs", it again check for the "AccRendered" which is not set to true.
    – Anurag
    Jun 8 '16 at 15:14
  • 1
    can you update the apex in question with changes you made?
    – Anurag
    Jun 8 '16 at 15:29
  • Controller code has been updated in original post.
    – Matt M
    Jun 8 '16 at 15:33
  • 1
    did you check the debugs to see the method is executed or not and what value of boolean "AccRendered" you are getting on page?
    – Anurag
    Jun 8 '16 at 15:46
  • 1
    Can you please check the browser console and see if you are getting any JavaScript error?
    – Saroj Bera
    Jun 8 '16 at 16:11
2

The boolean variable AccRendered is set to false in the constructor. Make AccRendered true in fetchOEs() method so it will get displayed.

2
  • I made that change (can't believe I didn't notice that) but it still doesn't respond to me clicking the name.
    – Matt M
    Jun 8 '16 at 15:25
  • can you look at the comments on the first post. I still can't get this to render.
    – Matt M
    Jun 8 '16 at 16:09
1

You can run into trouble if you put a rendered= on an outputPanel when the initial condition evaluates to false as the DOM <div> is never initially generated so the AJAX rerender logic has nothing to work with

 <apex:outputpanel id="pbOEs" rendered="{!AccRendered}">
    <apex:repeat value="{!OpenEnrollments}" var="OE">
        <apex:outputField value="{!OE.Start_Date__c}"/>
    </apex:repeat>
 </apex:outputpanel>

Better is

 <apex:outputpanel id="pbOEs" >
    <apex:repeat value="{!OpenEnrollments}" var="OE" rendered="{!AccRendered}">
        <apex:outputField value="{!OE.Start_Date__c}"/>
    </apex:repeat>
 </apex:outputpanel>

There is a famous blog post on this topic by the inestimable Bob Buzzard

1
  • I have updated the visualforce page code in original post with your suggestion. Still no go.
    – Matt M
    Jun 8 '16 at 16:51
0

Ok, I figure it out after all the help from the peeps on this post.

I needed to add Apex:form to the visualforce page and my controller needed a change in that my fetchOEs needed to be changed to pagereference.

Working Controller Code:

public class LicensingGridController {

    public Id selectedAccId {get; set;}
    public Boolean AccRendered {get; set;}

    public LicensingGridController(){
        AccRendered = FALSE;
    }
    //
    public List<BCS__c> getTheHubs() {
        List<BCS__c> hubs = [Select Id, Name, User__r.Name,
                             (Select Id,Account__c,Account__r.Name,Hub_Name__r.Name
                              FROM Account_Counselors__r),
                             (Select Name 
                              FROM Licenses__r)
                             FROM BCS__c
                             WHERE Inactive__C = FALSE];
        return hubs;
    }

    public list<OE_Rollover_Spans__c> getOpenEnrollments(){
        List<OE_Rollover_Spans__c> OEs = [Select Account__c,Account__r.Name,Name,OE_Type__c,Start_Date__c,End_Date__c
                                          FROM OE_Rollover_Spans__c
                                          WHERE Account__c = :selectedAccId];
        return OEs;
    }

    public PageReference fetchOEs(){
        AccRendered = TRUE;

        return null;

    }

}

Working VISUalForce page:

<apex:page controller="LicensingGridController" sidebar="false">
    <apex:form>
        <apex:pageBlock >
            <apex:pageBlockTable value="{!TheHubs}" var="Hub">
                <apex:column value="{!Hub.Name}" />
                <apex:column >
                    <apex:facet name="header">Licenses</apex:facet>
                    <ul>
                        <apex:repeat value="{!Hub.Licenses__r}" var="Lic">
                            <li><apex:outputField value="{!Lic.Name}" /></li>
                        </apex:repeat>
                    </ul>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">Accounts</apex:facet>
                    <ul>
                        <apex:repeat value="{!Hub.Account_Counselors__r}" var="Counselor">
                            <apex:outputpanel id="Accounts">
                                <li><apex:outputLabel value="{!Counselor.Account__r.Name}" / ></li>
                                    <apex:actionSupport event="onclick" action="{!fetchOEs}" rerender="pbOEs">
                                        <apex:param name="SelectedAcc" assignTo="{!SelectedAccid}" value="{!Counselor.Account__c}"/>
                                        <apex:param name="AccRendered" assignTo="{!AccRendered}" value="TRUE"/>
                                    </apex:actionSupport>
                                </apex:outputPanel>

                        </apex:repeat>

                    </ul>
                </apex:column>
                <apex:column headerValue="OE Dates">
                    <apex:outputpanel id="pbOEs" >
                        <apex:repeat value="{!OpenEnrollments}" var="OE" rendered="{!AccRendered}">
                            <li><apex:outputField value="{!OE.Account__r.Name}" /> <apex:outputField value="{!OE.Start_Date__c}" /></li>
                        </apex:repeat>
                    </apex:outputpanel>
                </apex:column>

            </apex:pageBlockTable>

        </apex:pageBlock>
    </apex:form>
</apex:page>

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.