Please Review my Code:: I have Created a Custom Component In which I have Created Check-boxes in from from each record and Now I want to retain there position but it is not happening as well my wrapper is fine can anybody please tell me what is the mistake.
.................................................
public class PaginationCompController {
public List<String> selectedFields{get;set;}
public String selectedObject{get;set;}
public String query{get;set;}
Public ApexPages.StandardSetController ssc{get;set;}
public List<sObject> allRecords{get;set;}
public Integer Size{get;set;}
public Integer pageNumber{get;set;}
public ID recId{get;set;}
public List<WrapperClass> listOfWrapper{get;set;}
//This method will called only once autmatically by the actionfuntion component and Initialize the ssc by the query
public void show(){
//get the query in the form of the String
//automatically Called By Action
allRecords();
}
//This method will return the list of all Records
public List<sObject> allRecords(){
allRecords = ssc.getRecords();
System.debug('this called' + allrecords);
pageNumber = ssc.getPageNumber();
recordsInWrapper();
return allRecords;
}
/*============================================ Methods for Pagination =============================================*/
public void first(){
ssc.first();
allRecords();
}
public void next(){
ssc.next();
allRecords();
}
public void previous(){
ssc.previous();
allRecords();
}
public void last(){
ssc.last();
allRecords();
}
public void pageSize(){
ssc.setPageSize(size);
allRecords();
}
public void finalPageNumber(){
ssc.setPageNumber(pageNumber);
allRecords();
}
/*==============================================MAINTAIN THE CHECKBOXES ===============================================*/
public Map<Id,sObject> mapOfSelectedRecords;
public void selectedRecords(){
mapOfSelectedRecords = new Map<Id,sObject>();
if(listOfWrapper!=null){
for(WrapperClass ob : listOfWrapper){
if(ob.isSelected == true){
//putting all the checked records to the Map
mapOfSelectedRecords.put(ob.obj.id, ob.obj);
}
else{
//Remove funtion is used to remove the all the Records which first selected and later deselected
mapOfSelectedRecords.remove(ob.obj.id);
}
}
}
System.debug('The map of selected records is ' + mapOfSelectedRecords);
}
/*============================================================= WRAPPPER CLASS =============================================================================*/
public class WrapperClass{
public Boolean isSelected {get;set;}
public sObject obj {get;set;}
public WrapperClass(sObject obj,Boolean isSelected)
{
this.isSelected = isSelected;
this.obj = obj;
}
}
public List<WrapperClass> recordsInWrapper(){
selectedRecords();
System.debug('Inside the records in Wrapper Methods The Map of selected Records is : ' + mapOfSelectedRecords);
listOfWrapper = new List<WrapperClass>();
System.debug('The wrapper data is ' +listOfWrapper );
System.debug('The all Records are ::::: ' + allRecords);
for(sObject sObj : allRecords){
if(mapOfSelectedRecords.containsKey(sobj.id)){
System.debug('Key is Present');
listOfWrapper.add(new WrapperClass(sObj,true));
}
else{
System.debug('Key is Not Present');
listOfWrapper.add(new WrapperClass(sObj,false));
}
}
System.debug('The wrapper data is ' +listOfWrapper );
// System.debug('The Checked wrapper data is ' +asRecordsList );
return listOfWrapper;
}
}
Aucun commentaire:
Enregistrer un commentaire