3

I have a data table and corresponding controller code. The code is not giving any error. However, the data is not getting populated. I have ensured that table gets rerender when a change event occurs. I am trying to figure this out for 2 days now, without any luck. believe it is something small that I am missing in the code.

Controller:

global with sharing class UserStatsController {


public string regn {get; set;}
public string dist {get; set;}    
public string OSR  {get; set;}

public List<User_Stats__c> User_Stats { get; set; }
public List<SalesRep> Sales_Reps { get; set; } 

public UserStatsController() {
Integer regnInt = (regn!=null) ? Integer.valueOf(regn) : -1;
User_Stats =[SELECT Id, Month__c, Total_Rental_Revenue_Actual__c, Rental_Revenue_Goal__c 
                FROM User_Stats__c 
                WHERE Year__c = '2013' and Sales_Rep__c =: OSR and Region__c =: regnInt and District__c =: dist and Sales_Rep__c != null and Rental_Revenue_Goal__c != null 
                ORDER BY Month__c];

// Populate list of SalesRep
Sales_Reps = new List<SalesRep>();
for(User_Stats__c us : User_Stats) {
    Sales_Reps.add(new SalesRep(us));
}
}


public class SalesRep implements Comparable {

public Integer compareTo(Object o) {
    return month-((SalesRep)o).month;
}

public User_Stats__c UserStat { get; set; }
public Integer month { get; set; }
public String monthString { get; set; }    

public SalesRep(User_Stats__c usrStat)
{
    this.UserStat = usrStat;
    this.month = integer.valueof(usrStat.Month__c);
    this.monthString = DateTime.newInstanceGMT(System.Date.newInstance(2000, month, 1), System.Time.newInstance(0, 0, 0, 0)).formatGMT('MMM');
}

public PageReference save() { 
update User_Stats; 
return null; 
}

}
    public list <SelectOption> getValuesr()
{
    list <selectoption> lsreg = new List<selectoption> ();
    lsreg.add(new SelectOption('', '--None--'));
    Set<String> regionSet = new Set<String>();
    for (User_Stats__C Rgn : [SELECT Region__c FROM User_Stats__C where Region__c != null and Region__c != 0 and Region__c != 1 and District__c != null and District__c != '0'])
    {
        String region = string.valueOf(Rgn.Region__c);
        if(!regionSet.contains(region)) lsreg.add(new selectoption(region, region));
        regionSet.add(region);
    }
    return lsreg;
}

public list <SelectOption> getValues()
{
    list <selectoption> ls = new List<selectoption> ();
    ls.add(new SelectOption('', '--None--'));
    Integer regnInt = (regn!=null) ? Integer.valueOf(regn) : -1;
    Set<String> distSet = new Set<String>();
    for (User_Stats__C dist : [SELECT District__c FROM User_Stats__c where Region__c =: regnInt and District__c != null and Region__c != null and Region__c != 1 and Region__c != 0])
    {
        if(!distSet.contains(dist.District__c)) ls.add(new selectoption(dist.District__c, dist.District__c));
        distSet.add(dist.District__c);
    }
    return ls;
}

public list <SelectOption> getValuesosr()
{
    list <selectoption> lsosr = new List<selectoption> ();
    lsosr.add(new SelectOption('', '--None--'));
    Integer regnInt = (regn!=null) ? Integer.valueOf(regn) : -1;
    Set<String> repSet = new Set<String>();
    for (User_Stats__C srep : [SELECT Sales_Rep__c FROM User_Stats__c where Region__c =: regnInt and District__c =: dist and District__c != null and Region__c != null and Region__c != 1 and Region__c != 0 ORDER BY Sales_Rep__c])
    {
        if(!repSet.contains(srep.Sales_Rep__c)) lsosr.add(new selectoption(srep.Sales_Rep__c, srep.Sales_Rep__c));
        repSet.add(srep.Sales_Rep__c);
    }
    return lsosr;
}


public List<User_Stats__c> getSalesReps(){
    Integer regnInt = (regn!=null) ? Integer.valueOf(regn) : -1;
    Sales_Rep=[Select Id, Month__c, Total_Rental_Revenue_Actual__c, Rental_Revenue_Goal__c From User_Stats__c where Year__c = '2013' and Sales_Rep__c =: OSR and Region__c =: regnInt and District__c =: dist and Sales_Rep__c != null and Rental_Revenue_Goal__c != null ORDER BY Month__c];
    Sales_Rep.sort();
    return Sales_Rep;
}
}

VF page:

<apex:pageblock >
   <apex:dataTable value="{!Sales_Reps}" var="rep" id="mnth" border="1" cellpadding="3" cellspacing="2" align="center" bgcolor="#F5FFFA">
    <apex:column headerValue="Sales Rep" value="{!rep.UserStat.Month__c}">
    </apex:column>
    <apex:column headerValue="Oct Rental Revenue" value="{!rep.UserStat.Total_Rental_Revenue_Actual__c}">
    </apex:column>            
    <apex:column headerValue="Oct Rental Goals" value="{!rep.UserStat.Rental_Revenue_Goal__c}">
    </apex:column>             
    <apex:column headerValue="Goal Revision">
        <apex:inputField value="{!rep.UserStat.Rental_Revenue_Goal__c}"/>
        <apex:commandButton action="{!save}" value="Save"/>
    </apex:column>            
</apex:dataTable>
</apex:pageBlock>

Please help. Thanks.

  • Is the issue that you have no rows in your table? Have you tried running your query logic from the constructor in the Developer Console to verify that the output is what you are expecting? – Michael Welburn Jan 21 '14 at 0:39
  • Yes. I debug the code using the console. This is what I found. WHERE Year__c = '2013' and Sales_Rep__c =: OSR and Region__c =: regnInt and District__c =: dist and Sales_Rep__c != null and Rental_Revenue_Goal__c != null is not generating data. however if I remove Sales_Rep__c =: OSR and Region__c =: regnInt and District__c =: dist, the data is getting populated. These 3 are values of select list that I have in the page and I have included a rerender statement after all of them. any idea why this is happening? – Robin Jan 21 '14 at 3:47
  • It is difficult to tell based on a subset of your code, but if you aren't generating any data in the console when those fields are set, that seems like it should explain why no data is coming back in your VF page? – Michael Welburn Jan 21 '14 at 4:24
  • I have updated my controller code to give info about the select list and other data table. I am sure that the data is getting generated in the console as I am using the same values from select list to populate other tables too and that is why this is so puzzling. – Robin Jan 21 '14 at 5:08
  • In the code above, the getSalesRep routine also uses values from select list in where condition, and it is generating values..but routine in question is not generating values.. – Robin Jan 21 '14 at 5:12
1

I don't think it's a rerender problem because you don't have rendered and rerender attributes there at all. Does the page "blink" when you submit it (full page refresh)?


I'd say your code does exactly what you told it to - nothing ;)

<apex:column headerValue="Goal Revision">
    <apex:inputField value="{!rep.UserStat.Rental_Revenue_Goal__c}"/>
    <apex:commandButton action="{!save}" value="Save"/>
</apex:column>

This tells us you have put save button in every single row - which is bit of no-no. You haven't made the save specific (for example by showing some column of checkboxes and "save selected"). It'd make more sense to just have 1 button at the top/bottom of page.

public PageReference save() { 
update User_Stats; 
return null; 
}

So your save method just saves some stuff (you'd have to check debug logs if the update is really fired but I think it should).

List<User_Stats__c> User_Stats is different collection than List<SalesRep> Sales_Reps. I think you're setting value on one object (which might be a full copy and not just a shallow reference) but fire the update against original (= unmodified) list.

I think you'd have to collect them back from the wrapper to helper List<SalesRep> and update the content of that list. And then - if you expect some magic to happen to other variables - you'd probably have to re-query something.

It's quite hard to follow your code. We don't need to see the compareTo() ;) Try nailing it down to smallest possible piece that still reproduces the problem and the answer might be easier to spot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.