function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Damien_Damien_ 

rerender not working correctly

I have a super simple page and a button with a rerender property.  All it should be doing is rerendering 2 different panels.  For some reason this rerender never happens, but I had put debugs in ensuring that my method does get called.  Any ideas?

 

Page

<apex:page controller="CohortTest2" sidebar="false">
	<apex:form >
		<apex:outputPanel id="pnl1" rendered="{!showMe}">
			<apex:outputText value="dum dum dum" />
		</apex:outputPanel>
		<apex:outputPanel id="pnl2" rendered="{!!showMe}">
			<apex:outputText value="blah blah blah" />
		</apex:outputPanel>
		<apex:commandButton value="button" action="{!test}" rerender="pnl1, pnl2" />
	</apex:form>
</apex:page>

 Controller:

public with sharing class CohortTest2
{
	public boolean showMe{get;set;}
	public CohortTest2()
	{
		showMe = false;
	}
	
	public void test()
	{
		showMe = !showMe;
		//return new PageReference('/apex/Cohort_SetupWizard2');
		//return null;
	}
}

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Chamil MadusankaChamil Madusanka

Try these changes

 

<apex:page controller="CohortTest2" sidebar="false">
    <apex:form >
        <apex:outputPanel id="pnl1" >
            <apex:outputText value="dum dum dum" rendered="{!showMe}"/>
        </apex:outputPanel>
        <apex:outputPanel id="pnl2" >
            <apex:outputText value="blah blah blah" rendered="{!!showMe}" />
        </apex:outputPanel>
        <apex:commandButton value="button" action="{!test}" rerender="pnl1, pnl2" />
    </apex:form>
</apex:page>

 Adding to previous reply. You cannot use rerender and rendered attributes for same component.

 

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

All Answers

Starz26Starz26

You have to rerender the parent:

 

<apex:page controller="CohortTest2" sidebar="false">
   
    <apex:form id="theForm">
        <apex:outputPanel id="pnl1" rendered="{!showMe}">
            <apex:outputText value="dum dum dum" />
        </apex:outputPanel>
        <apex:outputPanel id="pnl2" rendered="{!!showMe}">
            <apex:outputText value="blah blah blah" />
        </apex:outputPanel>
        <apex:commandButton value="button" action="{!test}" rerender="theForm" />
    </apex:form>
</apex:page>

 

Chamil MadusankaChamil Madusanka

Try these changes

 

<apex:page controller="CohortTest2" sidebar="false">
    <apex:form >
        <apex:outputPanel id="pnl1" >
            <apex:outputText value="dum dum dum" rendered="{!showMe}"/>
        </apex:outputPanel>
        <apex:outputPanel id="pnl2" >
            <apex:outputText value="blah blah blah" rendered="{!!showMe}" />
        </apex:outputPanel>
        <apex:commandButton value="button" action="{!test}" rerender="pnl1, pnl2" />
    </apex:form>
</apex:page>

 Adding to previous reply. You cannot use rerender and rendered attributes for same component.

 

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

This was selected as the best answer
Damien_Damien_

Wow, perfect chamil.  Thank you.  I can't believe I've been developing all this time and never known that simple thing..