1

I'm trying to replace the "header" facet inside a relatedList on my Visualforce page. Inside the header I want to put a commandButton that, when I click it, will hide (via rendered) the pageBlock that encases the relatedList(s). At the same time, other pageBlocks on the VF page will have their rendered boolean flipped so upon reRender they will be displayed.
Currently I am getting the reRender "flash" when I click the button but the relatedLists still remain and the other pageBlocks remain hidden.

Here is the relatedList pageBlock:

<apex:pageBlock id="relatedLists" rendered="{!showRelatedLists}">
    <apex:relatedList list="Injuries__r" subject="{!$CurrentPage.parameters.relatedId}">
        <apex:facet name="header">
            <apex:form>
            <apex:commandButton value="New Injury Case Detail" >
            <apex:actionSupport event="onclick" action="{!newCaseDetail}" reRender="accountBlock,relatedLists" />
            </apex:commandButton>
            </apex:form>
        </apex:facet>
    </apex:relatedList>
</apex:pageBlock>

below the relatedLists are the other pageBlocks I want to display upon clicking the commandButton:

<apex:form id="accountForm">
    <apex:pageBlock mode="detail" id="accountBlock" rendered="{!showCaseDetailForms}">
    {etc...}

here is the controller function being called by the actionSupport:

public PageReference newCaseDetail() {
    showCaseDetailForms = true;
    showRelatedLists = false;
    return null;
}

Here is the edited code after wrapping the pageblocks in outputpanels:
relatedlists block:

<apex:outputPanel id="relatedLists" rendered="{!showRelatedLists}">
<apex:pageBlock>
    <apex:relatedList list="Injuries__r" subject="{!$CurrentPage.parameters.relatedId}">
        <apex:facet name="header">
            <apex:form>
            <apex:commandButton value="New Injury Case Detail" >
                <apex:actionSupport event="onclick" action="{!newCaseDetail}" reRender="searchBlock" />
            </apex:commandButton>
            </apex:form>
        </apex:facet>
    </apex:relatedList>
</apex:pageBlock>
</apex:outputPanel>

other pageblocks section:

<apex:outputPanel id="searchBlock" rendered="{!showCaseDetailForms}">
<apex:form id="accountForm">
<apex:pageBlock mode="detail" id="accountBlock" rendered="{!showCaseDetailForms}">
{etc...}
0

Wrap the portion you want to rerender in an apex:outputpanel. Give that panel the rerender attribute and the id you're trying to rerender.

| improve this answer | |
  • Stephen, this solution isn't working for me. I wrapped the relatedList pageblock in an outputpanel, assigned it the id and the rendered attribute, then I wrapped the other page blocks in a second outputPanel with the other id and rendered attribute linked to the boolean in the controller. When I click the commandbutton I see the reRender 'flash' but nothing changes. – James Cary Feb 4 '16 at 20:39
  • Can you post your edited code? – Stephen Feb 4 '16 at 20:57
  • Also, you can use the action and rerender attributes of the commandbutton tag. Is there a reason you're using actionsupport? – Stephen Feb 4 '16 at 21:10
  • Since I was trying to hide the pageBlock section that contains the commandButton while simultaneously showing a different section of the page I thought the asynchronous action of actionSupport would help with this function call and reRender. If I move the action and rerender attributes to the commandButton, when I click the button it doesn't even do the reRender 'flash'. – James Cary Feb 4 '16 at 21:15
0

You are doing it wrong. Never rerender the same component in which you have give render condition otherwise it will never work for you.

<apex:form id="accountForm">

I think this is your main outer form . try to rerender it from your command button. It will solve your problem.

Also you can do this

<apex:commandButton value="New Injury Case Detail"  action="{!newCaseDetail}" reRender="accountForm">
</apex:commandButton>

instead of this

<apex:commandButton value="New Injury Case Detail" >
       <apex:actionSupport event="onclick" action="{!newCaseDetail}" reRender="accountForm" />
 </apex:commandButton>

Apply these two changes and your problem will be solved.

| improve this answer | |

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.