You need to sign in to do that
Don't have an account?
RKrish
Reg: Wrapper classes
Hi,
How can i return an integerlist and a string list from the wrapper class?
Suppose if,
I have integer list with values 10,20,30.
I have string list with values 'A','B','C'.
Using wrapper class i need to return integer list in first column, and string list in second column of page block table or any data list.
Thanks in Advance.
You can create the wrapper class in following manner:
public class DataTypeWrapper {
public Integer intValue{get;set;}
public String textValue{get;set;}
public DataTypeWrapper(Integer intValue, String textValue) {
this.intValue = intValue;
this.textValue = textValue;
}
}
form the other class you can populate this wrapper class list like :
public List<DataTypeWrapper> lisrWrapper{get;set;}
constructor(){
lisrWrapper = new List<DataTypeWrapper>();
for(Integer i=0; i<5;i++){
lisrWrapper.add(new DataTypeWrapper(i, 'text'));
}
}
VF page
<apex:pageBlockTable value="{!listWrapper}" var="item">
<apex:column headerValue="FirstColumn" value={!item.intValue}" />
<apex:column headerValue="SecondColumn" value={!item.textValue}" />
</apex:pageBlockTable>
All Answers
You can create the wrapper class in following manner:
public class DataTypeWrapper {
public Integer intValue{get;set;}
public String textValue{get;set;}
public DataTypeWrapper(Integer intValue, String textValue) {
this.intValue = intValue;
this.textValue = textValue;
}
}
form the other class you can populate this wrapper class list like :
public List<DataTypeWrapper> lisrWrapper{get;set;}
constructor(){
lisrWrapper = new List<DataTypeWrapper>();
for(Integer i=0; i<5;i++){
lisrWrapper.add(new DataTypeWrapper(i, 'text'));
}
}
VF page
<apex:pageBlockTable value="{!listWrapper}" var="item">
<apex:column headerValue="FirstColumn" value={!item.intValue}" />
<apex:column headerValue="SecondColumn" value={!item.textValue}" />
</apex:pageBlockTable>
Hi,
Try this.
public class Test
{
list<testWrapper> lstWrap = new list<testWrapper>();
public class testWrapper
{
public string str{get;set;}
public integer i{get;set;}
public testWrapper(integer i, string str)
{
this.i = i;
this.str = str;
}
}
public list<testWrapper> getlstWrap()
{
lstWrap.add(new testWrapper(10,'A'));
lstWrap.add(new testWrapper(20,'B'));
lstWrap.add(new testWrapper(30,'C'));
return lstWrap;
}
}
display the lstWrap in Pageblock Table or Data Table.
Regards,
Shravan
Hi,
I have two custom objects Obj1 & Obj2 with standard field 'name'.
how can i return both these list values from the wrapper class.
I need to place these 2 list of values in different page block tables.
Thanks in advance.
Hi Krish,
wrapper class returns only single list of data. This list can we place only in single pageblock table.So, If you want to place data in different pageblocktables, you have to write query to get the list of records for both objects. Here, there is no need of writing wrapper class. prepare list for both objects individually then return to pageblocktable.