You need to sign in to do that
Don't have an account?
Mak One
Want to pass List in constructor without specifying type as it can take list of any type
I am writing a wrapper class to to show atmost 100 elements of list using offset:
class Pg{
public Integer displayLimit{get;set;}
public Integer displayOffset{get;set;}
public Boolean disableNext{get;set;}
public Boolean disablePrev{get;set;}
List collection;
public Pg(){}
public Pg(List collection){
this.collection=collection;
this.displayOffset=0;
this.displayLimit=100;
this.disablePrev=true;
if (this.collection.size()>displayLimit) {
this.disableNext=false;
} else {
this.disableNext=true;
}
}
public void next(){
this.displayOffset=this.displayOffset+displayLimit;
if (this.collection.size()<displayOffset+displayLimit) {
this.disableNext=true;
}
this.disablePrev=false;
}
public void prev(){
this.displayOffset=this.displayOffset-displayLimit;
if (this.displayOffset==0) {
this.disablePrev=true;
}
this.disableNext=false;
}
}
But here it is not allowing me to give List collection;
It needs something like List<Object> collection. Expecting Angle bracket after List.
But I want that I should able to pass List of any collection in constructor.
How to achieve this?
class Pg{
public Integer displayLimit{get;set;}
public Integer displayOffset{get;set;}
public Boolean disableNext{get;set;}
public Boolean disablePrev{get;set;}
List collection;
public Pg(){}
public Pg(List collection){
this.collection=collection;
this.displayOffset=0;
this.displayLimit=100;
this.disablePrev=true;
if (this.collection.size()>displayLimit) {
this.disableNext=false;
} else {
this.disableNext=true;
}
}
public void next(){
this.displayOffset=this.displayOffset+displayLimit;
if (this.collection.size()<displayOffset+displayLimit) {
this.disableNext=true;
}
this.disablePrev=false;
}
public void prev(){
this.displayOffset=this.displayOffset-displayLimit;
if (this.displayOffset==0) {
this.disablePrev=true;
}
this.disableNext=false;
}
}
But here it is not allowing me to give List collection;
It needs something like List<Object> collection. Expecting Angle bracket after List.
But I want that I should able to pass List of any collection in constructor.
How to achieve this?
But now I am unable to referer to variables in that list inside Visualforce Page. :(
get set this on VF and then reference it ..
say, for example, list is populated as follows ..
public list<Object> getobjList(){
list<Object> objList = new list<Object>();
objList.add('item 1');
objList.add('item 2');
objList.add(3);
objList.add([select id from Account limit 2]);
return objList;
}
then VF page can display like this ..
<apex:pageBlockTable value="{!objList}" var="item">
<apex:column headerValue="Item" value="{!item}" />
</apex:pageBlockTable>
or ..
<apex:outputText value="{!objList[3][0]}" />
will display the first item in the list (the Account query) which is the last element of the objList.
When it is wrapper then objList[3][0].some_Wrapper_Class_Field.
And what Visualforce page knows if it is List of Object so it does NOT contain any of fields like some_Field_Of_Standard_Object, some_Wrapper_Class_Field.