Most of peoples wanted to display the table if the list has records. For this you can use the below approach,
Apex Class:
Visualforce Page:
Apex Class:
- public class AccountController
- {
- public List<Account> accList{get; set;}
- public AccountController()
- {
- accList = [SELECT Id, Name FROM Account LIMIT 10];
- }
- }
Visualforce Page:
- <apex:page controller="AccountController">
- <apex:pageBlock title="Account List" >
- <apex:outputPanel rendered="{! IF(ISBLANK(accList), false, true) }">
- <apex:pageBlockTable value="{!accList}" var="acc" rendered="{!accList.size > 0}">
- <apex:column headerValue="Account Name"> {!acc.Name} </apex:column>
- </apex:pageBlockTable>
- </apex:outputPanel>
- </apex:pageBlock>
- </apex:page>
Two conditions are checked in the above visualforce page,
Condition 1:
{!IF(ISBLANK(accList), false, true)}
This will ensure to prevent from displaying table in the following conditions,
1. LIST not yet initialized.
2. LIST has been initialized, but no records.
Condition 2:
{!accList.size > 0}
Table will be displayed only if the LIST contains at least one record.
No comments:
Post a Comment