+ Start a Discussion
rpsfdcrpsfdc 

Rerender issue with datatable in Visualforce page

Hi,

In my visualforce page, i want to rerender a table after the user inputs value in the table. The last column in this table of each row is a simple formula field that sums up the values for other fields (e.g. June volume = 100, July Volume = 200 then the last column of Total will be 300). My VF page is like this:

<apex:page standardcontroller="Annual_Supply_Plan__c" sidebar="false" extensions="annualSupplyPlanController">
 
  <apex:form >
  <apex:pageBlock title="Annual Supply Plan Objects">
 
      <apex:dataTable value="{!listASPItems}" var="listASPItem" border="1" style="height:20;float: left;" id="ASPItemstable">
          
	  <apex:column headerValue="FY'11 Initial Shipment Forecast" width="5px" footerValue="Total">
              <apex:outputField value="{!listASPItem.Product_Category__c}" style="align: center" />
          </apex:column>
          
          <apex:column headerValue="June" width="5px" footerValue="Total June">
              <apex:inputField value="{!listASPItem.June_Volume__c}"/>
          </apex:column>
          
          <apex:column headerValue="July" footerValue="Total July">
              <apex:inputField value="{!listASPItem.July_Volume__c}"/>
          </apex:column>
          
              
          <apex:column headerValue="Tons" footerValue="Total">
             <apex:outputPanel id="shipmentForecasts">
              <apex:outputField value="{!listASPItem.Total_Volume__c}"/>
             </apex:outputPanel>
          </apex:column>
      </apex:dataTable>
      
    <apex:pageBlockButtons >
        <apex:commandButton action="{!SaveForecasts}" value="Save Forecasts" reRender="shipmentForecasts, {!listASPItems}"/>
    </apex:pageBlockButtons>

    </apex:pageblock>
  </apex:form>
 
 
</apex:page>

 But after clicking Save Forecasts, the table (last column specifically) is not refreshed. Can anyone please help me?

 

My controller is very simple:

public with sharing class annualSupplyPlanController {
    
    List<ASP_Item__c> listASPItems = new List<ASP_Item__c>();
    
    List<ASP_Yearly_Forecast__c> listASPYrlyFcsts = new List<ASP_Yearly_Forecast__c>();
    
    public id idASP = System.currentPageReference().getParameters().get('id');
    
    
    
    public annualSupplyPlanController(ApexPages.StandardController controller) {
    	
    	System.debug(logginglevel.INFO, 'in CreateASPItems listASP is '+ ApexPages.currentPage().getParameters().get('id'));
        
        listASPItems = [Select a.September_Volume__c, a.Product_Category__c, a.October_Volume__c, a.November_Volume__c, a.Name, a.Month__c, 
        				a.May_Volume__c, a.March_Volume__c, a.June_Volume__c, a.July_Volume__c, a.January_Volume__c, a.Id, a.February_Volume__c, a.December_Volume__c,
        				a.Date_of_Month__c, a.August_Volume__c, a.April_Volume__c, a.Annual_Supply_Plan__c, a.Total_Volume__c From ASP_Item__c a 
        				where a.Annual_Supply_Plan__c =: idASP order by a.Product_Category__c, a.Date_of_Month__c];
        
    }
    
    public List<ASP_Item__c> getlistASPItems(){
        return listASPItems;
    }
    
	public List<ASP_Yearly_Forecast__c> getlistASPYrlyFcsts(){
		return listASPYrlyFcsts;
	}
	
	public PageReference SaveForecasts() {
            update listASPItems;
            
            return null;
      }

      public PageReference cancel() {
            return null;
      }
	

}

 Appreciate your help.

 

Best Answer chosen by Admin (Salesforce Developers) 
WizradWizrad

After you update listASPItems in the following code, requery for it.

 

Edit: I would also recommend rerendering your entire table as opposed to one column in it.  And I have never seen someone trying to rerender a list.  Im suprised that compiles.

 

	public PageReference SaveForecasts() {
            update listASPItems;
            
            return null;
      }

All Answers

WizradWizrad

After you update listASPItems in the following code, requery for it.

 

Edit: I would also recommend rerendering your entire table as opposed to one column in it.  And I have never seen someone trying to rerender a list.  Im suprised that compiles.

 

	public PageReference SaveForecasts() {
            update listASPItems;
            
            return null;
      }
This was selected as the best answer
rpsfdcrpsfdc

Hello Wizrad, your magic worked. I was under the impression that rerendering could cause the constructor (where my query originally was) to be called again and hence the query would fire again.

This is how my new code looks like (just highlights). 

Is this an efficient way of doing it?

 

public with sharing class annualSupplyPlanController {
    
    List<ASP_Item__c> listASPItems = new List<ASP_Item__c>();
    
    public annualSupplyPlanController(ApexPages.StandardController controller) {
        
        listASPItems = [<Select SOQL query>];
         }

public PageReference SaveForecasts() {
            
            update listASPItems;
            this.listASPItems = [<Select SOQL query>];

       return null;
      }
}        

 

 

Earlier i was rerendering the entire table. But during debugging, i just tried to rerender a particular column and list. Thank you for pointing this out.

 

Cheers!!

WizradWizrad

Yeah thats the correct way of doing it.

 

Ultimately youre going to have to query a second time like that to see the formula fields update.

 

I guess you could just perform the transformations that the formula field does within apex, and then you wouldnt have to requery, but I would say that would be an inferior implementation.

rpsfdcrpsfdc

Got it!!

Thank you again for your time and advice. Appreciate it.