Saturday, July 26, 2014

Repeater Usage in Visualforce Page.

Repeater Usage in Visualforce Page.


Hi,
In this post i am giving an example of how to use <apex:repeat> tag in Visualforce page.


Controller Class: 

Public class TableController{
 public List<Account> accList{get;set;}

 Public TableController(){
  accList= new List<Account>();
  accList= [select id,name,type,industry from Account];
 }
}

Visualforce Page Class:

<apex:page controller="TableController" showheader="true" sidebar="false">
 <apex:form >
   <table border="1" width="650Px">
    <tr> 
      <th> Account Name</th>
      <th> Type  </th>
      <th> Industry</th>
    </tr>
    
    <apex:repeat value="{!accList}" var="a">
      <tr>
        <td> {!a.Name} </td>
        <td> {!a.type} </td>
        <td> {!a.industry} </td>
      </tr>
     </apex:repeat>
   </table>

 </apex:form>
 </apex:page>


Test Class:

@isTest
Public class PagblockTable_Test {
 static testmethod void testPageblockTable(){
  //Test converage for the myPage visualforce page
  PageReference pageref = Page.RepeatorExample;
  Test.setCurrentPageReference(pageref);
  
  // create an instance of the controller
  TableController tc= new TableController();
  
 }
}


out put :

save image



If we observe the output of VF page while using <apex:repeat> tag there is no default salesforce styles applied. suppose if you use pageBlock table then salesforce default styles will apply. if you want to apply your custom styles for table and columns you can apply with <apex:repeat> tag.









0 comments:

Post a Comment

 
| ,