Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thams017/c44780f64e16f1f34c77051b9de050a9 to your computer and use it in GitHub Desktop.
Save thams017/c44780f64e16f1f34c77051b9de050a9 to your computer and use it in GitHub Desktop.
This page will hide and show the output panel when a button is clicked.
public class RenderExampleClass {
/****get set varaible which will carry the true or false condition to the page****/
public Boolean showPanelHistory{ get; set;}
/****get set varaible which carry the list of accounts to the page****/
public Account accountList{ get; set;}
/****Acction method which is used in the page which acts like switch*****/
public PageReference showpanel(){
if(showPanelHistory == false) {
showPanelHistory = true;
}
else if(showPanelHistory == true){
showPanelHistory = false;
}
return null;
}
/***Example methos that to query the list of accounts***/
public void accountList(){
accountList = [
SELECT Id,
Name,
Type
FROM Account
];
}
/***** Setting up showPanelHistory = false directly in constructor
so when page loads the switch willl be in false condition********/
public RenderExampleClass() {
showPanelHistory = false;
}
}
<apex:page controller="RenderExampleClass">
<apex:form >
<apex:commandButton value="Show Section" action="{!showpanel}" rerender="showpanel">
</apex:commandButton>
<apex:outputPanel id="showpanel">
<apex:outputPanel rendered="{!showPanelHistory}">
<apex:pageBlock title="List of Accounts">
<apex:pageBlockSection >
<apex:outputField value="{!accountList.Name}"/>
<apex:outputField value="{!accountList.Type}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
</apex:outputPanel>
</apex:form>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment