Sample Wrapper Class using Apex in Salesforce
Sample Code:
Visualforce Page:
<apex:page controller="Sample" tabStyle="Account">
<apex:form >
<apex:pageMessages />
<apex:pageBlock id="pg">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!listWrapper}" var="a">
<apex:column >
<apex:inputCheckbox value="{!a.checkBool}"/>
</apex:column>
<apex:column value="{!a.acct.Name}"/>
<apex:column value="{!a.acct.Industry}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Controller:
public class Sample {
public List<WrapperClass> listWrapper {get;set;}
public Sample() {
List<Account> listAcct = [SELECT Name, Industry FROM Account LIMIT 1000];
if(listAcct.size() > 0) {
listWrapper = new List<WrapperClass>();
for(Account a : listAcct) {
listWrapper.add(new WrapperClass(a));
}
}
}
public class WrapperClass {
public Boolean checkBool {get;set;}
public Account acct {get;set;}
public WrapperClass(Account acct) {
this.acct = acct;
}
}
}
Output:
Visualforce Page:
<apex:page controller="Sample" tabStyle="Account">
<apex:form >
<apex:pageMessages />
<apex:pageBlock id="pg">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!listWrapper}" var="a">
<apex:column >
<apex:inputCheckbox value="{!a.checkBool}"/>
</apex:column>
<apex:column value="{!a.acct.Name}"/>
<apex:column value="{!a.acct.Industry}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Controller:
public class Sample {
public List<WrapperClass> listWrapper {get;set;}
public Sample() {
List<Account> listAcct = [SELECT Name, Industry FROM Account LIMIT 1000];
if(listAcct.size() > 0) {
listWrapper = new List<WrapperClass>();
for(Account a : listAcct) {
listWrapper.add(new WrapperClass(a));
}
}
}
public class WrapperClass {
public Boolean checkBool {get;set;}
public Account acct {get;set;}
public WrapperClass(Account acct) {
this.acct = acct;
}
}
}
Output:
No comments:
Post a Comment