Visualforce rendered attribute example Explained

Visualforce rendered,visualforce rendered attribute example,rerender and renderAs,salesforce panda, panda bear, panda, sfdc, sfdc panda, dineshkumar rajamani, dinesh dk, salesforce example, salesforce tutorial, cloud technology, salesforce training, salesforce training in chennai,rendered rerender renderas in salesforce

Visualforce Rendered Attribute Example Technical Explanation :-

Rendered attribute example i have written to explain the use case across visualforce pages before that we will see the technical explanation.

The rendered attribute is a Boolean value, it has true as default value and based on the value it will show or hide a page block or a field on the VF pages.

You can also use a IF condition inside rendered attribute to show results based on a criteria like below piece of code,

<apex:inputField id="Id1" value="{!Obj.Field1}" rendered="{!IF(Obj.fieldname = 'dk'|| Obj.fieldname = 'Dinesh' ,true,false)}"/>

In the below class constructor i am fetching a single record from account object and setting PBFlag to false which applied to rendered attribute on VF page and makes the pageblock to get hided.

Note: ***When the visualforce page is initially loaded, controller constructor will be called and the values will be loaded***

Apex Class(Visualforce Rendered attribute Example explained) :-

Public class renderedExample{
  Public Boolean PBFlag{get;set;}
  Public Account[] accRec{get;set;}

Public renderedExample(){
  accRec = [select name,id,accountnumber from account limit 1];

PBFlag= false;

Public void ShowPB(){
  PBFlag= true;

when you click on the button “Click me ..” in VF page it will make a call to controller method “ShowPB” and in that method am setting Pb Flag to true which in turn makes the pageblock visible.

VF Page(Visualforce Rendered attribute Example explained) :-

<apex:page controller="renderedExample">

<apex:form >
  <apex:pageBlock >
  <apex:commandButton value="Click me to set render attribute to true to show pageblock table " action="{!ShowPB}"/>

<apex:pageBlock rendered="{!PBFlag}">
  Account Name :<apex:outputField value="{!accRec[0].name}"/>
  Account Number :<apex:outputField value="{!accRec[0].accountnumber}"/>

For more on apex:actionFunction component :-

Be the first to comment

Leave a Reply

Your email address will not be published.