Hi,
You can understand Wrapper like this.If you want to make a object which includes both( account and contact) or( account and its corresponding selection check box) you use wrapper class
<apex:page sidebar="false" controller="WrapTest ">
<!--VF PAGE BLOCK-->
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!ProcessSelected}" value="Show Selected accounts" reRender="block2"/>
</apex:pageBlockButtons>
<apex:pageBlockSection columns="2">
<apex:pageBlockTable value="{!wrapaccountList}" var="waccl">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox />
</apex:facet>
<apex:inputCheckbox value="{!waccl.isSelected}" id="InputId"/>
</apex:column>
<apex:column value="{!waccl.accn.name}"/>
<apex:column value="{!waccl.accn.phone}"/>
<apex:column value="{!waccl.accn.billingcity}"/>
</apex:pageBlockTable>
<apex:pageBlockTable value="{!selectedAccounts}" var="sa" id="block2">
<apex:column value="{!sa.name}"/>
<apex:column value="{!sa.phone}"/>
<apex:column value="{!sa.billingcity}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller -
public class WrapTest {
//CONTROLLER CLASS
public list<wrapaccount> wrapaccountList { get; set; }
public list<account> selectedAccounts{get;set;}
public WrapTest (){
//if(wrapaccountList ==null){
wrapaccountList =new list<wrapaccount>();
for(account a:[select id,name,billingcity,phone from account limit 10]){
wrapaccountlist.add(new wrapaccount(a));
}
// }
}
//### SELECTED ACCOUNT SHOWN BY THIS METHOD
public void ProcessSelected(){
selectedAccounts=new list<account>();
for(wrapaccount wrapobj:wrapaccountlist){
if(wrapobj.isSelected==true){
selectedAccounts.add(wrapobj.accn);
}
}
}
//##THIS IS WRAPPER CLASS
// account and checkbox taken in wrapper class
public class wrapaccount{
public account accn{get;set;}
public boolean isSelected{get;set;}
public wrapaccount(account a){
accn=a;
isselected=false;
}
}
}
Hope this helps.