+ Start a Discussion
Collen Mayer 6Collen Mayer 6 

reRender Column Heading

Hi All,
I have a visual force page that allows a user to enter/edit their mileage expenses.  All is working fine, but I'm needing to have a column heading rerender when a user hits a "refresh programs" button, but I'm not having any luck.  Here is a simplified version of the page:
 
<apex:page standardController="Expense_Report__c" extensions="addMileageExpense" sidebar="false" showHeader="true">
 <apex:form >		
 		<apex:pageBlock title="Mileage Report" id="er" >
    <table>     
      <tr>
          <td style="width:85px">
          		<h2>Program 1:</h2>
          </td>
          <td style="width:175px">
          		<apex:inputField value="{!Expense_Report__c.Program_1_Mileage_log__c}">          
           		</apex:inputField>
     	  </td>
        <td><apex:commandButton value="Refresh programs" action="{!refreshProgram}" reRender="program_num"></apex:commandButton></td>
        </tr>
    </table>
            <apex:pageMessages />
 		<apex:variable var="rowNumber" value="{!0}"/>
               <apex:pageblockSection columns="1" > 
 					
                   <apex:pageBlockTable title="Mileage Expenses" var="me" value="{!expenseList}" > 
  
 					<apex:column headerValue="Entry" style="width:20px; text-align:center;" headerClass="centertext">
 						<apex:outputText value="{0}" style="text-align:center;"> 
 							<apex:param value="{!rowNumber+1}" /> 
 						</apex:outputText>
					</apex:column> 
 					
                    <apex:column headerValue="Date of trip" >
                       <apex:inputField value="{!me.Date__c}"  required="true"/>
 					                    </apex:column>
                    
                    <apex:column headerValue="Purpose and Description" >
                       <apex:inputField value="{!me.Name}" required="true"/>
 					</apex:column> 
                    <apex:column headerValue="{! Expense_Report__c.Program_1_Number__c}" 
                                 style="width:50px" id="program_num">
                        <apex:inputField value="{!me.Prgm_1_Miles__c}" style="width:50px">
                        </apex:inputField>
                    </apex:column>
                 </apex:pageBlockTable>
             </apex:pageblockSection>                            
 		</apex:pageBlock> 		
 	</apex:form> 
 </apex:page>

The refresh program button simply upserts the existing expense report record after the "program 1" field is changed (and this is working ).  What I'm having problems with is getting the last column heading to rerender after the user changes program and hits the refresh program button.  The last column heading, Expense_Report__c.Program_1_Number__c, is a formula field based on program 1.  On a side note, if I refresh my browser after hitting refresh programs button, it does update the column heading, but  I'm trying to do this without refreshing the whole page. 

I'm new to visualforce so any help/advice is appreciated.

Best,
Collen
Best Answer chosen by Collen Mayer 6
Collen Mayer 6Collen Mayer 6
Thanks, TK, for getting me on the right track about refreshing the whole page.  That didn't exact code didn't work but something very close did:
 
public PageReference refreshProgram(){
	upsert reports;    
    PageReference tempPage = ApexPages.currentPage();            
            tempPage.setRedirect(true);
        return tempPage ;
 }



 

All Answers

Tarun Khatri (TK)Tarun Khatri (TK)
Hello Collen,

Try using below code for Command button:
<apex:commandButton value="Refresh programs" action="{!refreshProgram}" reRender="er"></apex:commandButton></td>

-Thanks,
TK

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Collen Mayer 6Collen Mayer 6
Thanks, TK.  What seems to be happening now with the code you suggest is that is that it rerenders and then updates the record.  So for the program field if my old value is "program 1" and my new value is "program 2", when I enter the new value in the field and hit the button, it reverts to program 1 on the screen and then upserts the old value.  My hope is to update the value "program 2" and then rerender the screen so the column heading has the new value for the field "program 2 number".  Any additional thoughts?

In case its helpful, my underlying function for {!refreshProgram} is simply:
 
public void refreshProgram(){
 upsert reports;  
 }

where reports is the expense report record. 
Tarun Khatri (TK)Tarun Khatri (TK)
Do you have getter and setter for expenselist variable? If so, put a debug log in refreshProgram function and check the values in it.
Collen Mayer 6Collen Mayer 6
Thanks, TK, for the help troubleshooting. 

So it turns out that my issue is that the heading that I'm trying to refresh is a formula field, and apparently the formula fields do not recalculate on reRender.  Does anyone have thoughts on how I could do this?  The formula field is based on a lookup field (Program) that I am updating. 
Tarun Khatri (TK)Tarun Khatri (TK)
Update your method to return pagereference as null and remove rerender attribute from command button. It will refresh whole page and you will get updated values.
 
public PageReference refreshProgram(){
 upsert reports;  
return null;
 }

-Thanks,
TK
Collen Mayer 6Collen Mayer 6
Thanks, TK, for getting me on the right track about refreshing the whole page.  That didn't exact code didn't work but something very close did:
 
public PageReference refreshProgram(){
	upsert reports;    
    PageReference tempPage = ApexPages.currentPage();            
            tempPage.setRedirect(true);
        return tempPage ;
 }



 
This was selected as the best answer