Using component in Visualforce

U

Some Visualforce components, such as <apex:pageBlockTable> or <apex:dataTable>, allow you to display information from multiple records at a time by iterating over a collection of records. To illustrate this concept, the following page uses the <apex:pageBlockTable> component to list the available job positions:

Visual Force Code:
<apex:pageblocktable value=”{!lstObjects}” var=”posts”>
<apex:column headerValue=”Name”> <apex:outputLink value=” !URLFOR($Action.positions__c.View,posts.id)}” target=”_blank”>{!posts.position_title}</apex:outputLink>
</apex:column>
<apex:column value=”{!posts.status}” headerValue=”Status”/>
<apex:column value=”{!posts.state}” headerValue=”State”/>
<apex:column value=”{!posts.city}” headerValue=”City”/>
<apex:column value=”{!posts.min_exp}yrs ” headerValue=”Experience Required”/>
<apex:column value=”{!posts.industry}” headerValue=”Industry”/>
<apex:column headerValue=”View Candidates”>
<apex:outputLink value=”/apex/Position_View”>View
<apex:param name=”position” value=”{!posts.position_title}”/>
</apex:outputLink>
</apex:column>
</apex:pageblocktable>

APEX code:
public class PositionSearch
{
List<positions__c> retresults = new List<positions__c>();
public List<PositionSearch> lstObjects {get; set;}
public PageReference defaultPositions()
{
lstObjects = new List<PositionSearch>();
retResults = [Select id, name,status__c,state__c, city__c,experience__c,industry__c from positions__c];        for(positions__c pos: retResults)
{
PositionSearch tmp = new PositionSearch();
tmp.position_title = pos.name;
tmp.state = pos.state__c;
tmp.city = pos.city__c;
tmp.industry = pos.industry__c;
tmp.status = pos.status__c;
tmp.min_exp = pos.experience__c;
tmp.id = pos.id;
lstObjects.Add(tmp);
}
return null;
}
}

The <apex:pageBlockTable> Component

Like other iteration components, <apex:pageBlockTable> includes two required attributes, value and var:

  • value takes a list of sObject records or values of any other Apex type. In the example above, {!lstObjects} is the list of queried data.
  • var specifies the name of the iteration variable. This variable is used within the body of the <apex:pageBlockTable> tag to access the fields on each contact. In this example, value=”{!posts}” is used on the <apex:column> tag to iterate through the returned list.

Note:
The <apex:pageBlockTable> component automatically takes on the styling of a standard Salesforce list. To display a list with your own styling, use <apex:dataTable> instead.

 

 

 


About the author

ankit.shah
By ankit.shah

Category