function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
iceberg4uiceberg4u 

Problems with data binding.


I have a list on whose columns I have applied sorting.The functionality works perfectly well.The problem arises when I try to sort on the columns regularly sometimes they loose values and sometimes they work well without any problems.

I had logged a case in Salesforce but,the reply was:->
"
Currently Salesforce does not support the VisualForce. For assistance with this you would need to go to www.Salesforce.com/Developers for assistance with this issue.
"
Please advise.


Message Edited by iceberg4u on 01-20-2009 10:29 PM
andresperezandresperez

Hi,

 

I have done sorting on lists without problems... 

 

Please post some of the code to see if there are any problems.

iceberg4uiceberg4u
public pagereference sortbyCompanyWebsite()
    {
        SetSortDirection(m_COLCompanyWebsite);                          //for setting direction            
        List<ActionAlertsDetailBO> tempList = new List<ActionAlertsDetailBO>();         //temporary List of the original or sorted data
        List<String> sortStringfield = new List<String>();      //the string list that will store all the values
               
        //Populating temporary list of records for sorting
        for(Integer i = 0 ; i < m_ActionAlertsDetailBO.size() ; i++)   
        {
            tempList.add(m_ActionAlertsDetailBO[i]);
        }
           
        //Populating temporary list of values for sorting
        for(Integer j = 0 ; j < m_ActionAlertsDetailBO.size() ; j++)
        {
                sortStringfield.add(tempList[j].AgreementStatusStringVal); 
                System.debug('tempList[j].CompanyWebsite:::::::'+tempList[j].AgreementStatusStringVal);
        }
       
        //Sort the list of values
        //this.SortDir=false;
        sortStringfield = sortData(sortStringfield,this.SortDir);
         for(Integer j = 0 ; j < m_ActionAlertsDetailBO.size() ; j++)
        {
               
                System.debug('tempList[j].CompanyWebsite:::::::'+sortStringfield[j]);  
        }  
        m_ActionAlertsDetailBO.clear();
           
        //Populate list of records according to sorted list of values
        for(Integer i = 0 ; i < sortStringfield.size() ; i++)
        {
            for(Integer j = 0 ; j < tempList.size() ; j++)
            {
                if(sortStringfield[i].equals(tempList[j].AgreementStatusStringVal))
                {                                                       //for duplicate names there are problems coming up One will have to verify some primary key as well
                    m_ActionAlertsDetailBO.add(tempList[j]);
                    tempList.remove(j);
                    break;
                }
            }
        }
        for(Integer i = 0 ; i < sortStringfield.size() ; i++)
        {
            System.debug('The website sorted is:' + m_ActionAlertsDetailBO[i].AgreementStatusStringVal);
        }     
        return null;    
    }
andresperezandresperez

Hi,

I have few comments about your code

  1. I notice you use System.debug() a lot... (which is great) Have you been able to trace down where the data gets lost?
  2. For the nested loop at the bottom, I suggest using the Map<String,String> construct.
  3. I have been building a generic sorter that I will post here as son as I finish it. (today or tomorrow)
iceberg4uiceberg4u

1)Actually I removed some System.debugs.The method is being called when the column header of the list is clicked.The sorting occurs properly but the values are lost in the main list as soon as it reaches the function itself.I do not understand what is occuring here.I get a lot of nulls.

 

2) I tried using Map but the same thing occurred.

 

3)Most people advised removing the "remove" portion from the "for" loop but I need to use it.Therefore I modelled the function in such a way so that it breaks immediately after a remove operation occurs.

 

andresperezandresperez

Hi,

  1. Are you using AJAX in the click of the column header? If not, the sorting could be working, but the page is refreshed which makes the list be be recreated.
  2. You are sorting by website (based on the method name), but here the field that you are using to sort is "AgreementStatusStringVal" should it say somthing like "website"?
  3. You can get rid of the "remove" operation by using a map. Something like this:

public pagereference sortbyCompanyWebsite() { SetSortDirection(m_COLCompanyWebsite); Map<String, ActionAlertsDetailBO> tempMap = new Map<String, ActionAlertsDetailBO>(); List<String> sortStringfield = new List<String>(); for(Integer i = 0 ; i < m_ActionAlertsDetailBO.size() ; i++) { // Populating temporary list of records for sorting tempMap.put(tempList[i].AgreementStatusStringVal, m_ActionAlertsDetailBO[i]); //Populating temporary list of values for sorting sortStringfield.add(tempList[i].AgreementStatusStringVal); System.debug('tempList[i].CompanyWebsite:::::::'+tempList[i].AgreementStatusStringVal); } //Sort the list of values // I assume you use something like List<>.sort()? sortStringfield = sortData(sortStringfield,this.SortDir); for(Integer j = 0 ; j < m_ActionAlertsDetailBO.size() ; j++) { System.debug('tempList[j].CompanyWebsite:::::::'+sortStringfield[j]); } m_ActionAlertsDetailBO.clear(); //Populate list of records according to sorted list of values for (String sortKey : sortStringfield) { m_ActionAlertsDetailBO.add(tempMap.get(sortKey)); } /* for(Integer i = 0 ; i < sortStringfield.size() ; i++) { System.debug('The website sorted is:' + m_ActionAlertsDetailBO[i].AgreementStatusStringVal); } */ for (String sortKey : sortStringfield) { System.debug('The website sorted is:' + tempMap.get(sortKey).AgreementStatusStringVal); } return null; }

 

Message Edited by andresperez on 01-21-2009 09:15 AM
mtbclimbermtbclimber

iceberg4u wrote:

I had logged a case in Salesforce but,the reply was:->
"
Currently Salesforce does not support the VisualForce. For assistance with this you would need to go to www.Salesforce.com/Developers for assistance with this issue.
"

 

This is not an accurate statement. There are varying degrees of support based on your agreements with salesforce.com but there is no policy that would make the above statement true. We are taking steps to rectify this inconsistency.

 

Apologies,

andresperezandresperez

Hi,

 

As promised, I just posted the sorter class (Link) I started building this morning... Hopefully it helps.