+ Start a Discussion
Noor FazliNoor Fazli 

Database updates on actionsupport are not getting displayed on rerendering of form

We are using actionsupport to  make database changes and we want to display those changes on the rerendering of the form.
Rerendering is working in the sense that its doing the page refresh but it does not reflect the database changes. When we do manual refresh than we are able to see the changes. What should be done.(actually I have tried using outputPanels also, but it looks like database update and page refresh are disconnected events). How to display new values on page refresh?

-- Here is the Visual force code
 
<apex:form id="mainFormId">
 <apex:pageBlock id="NR" >
 <apex:pageBlockButtons location="Top">
 <apex:commandButton value="Notification to Invoice" action="{!processSelected}" immediate="false">
 <apex:actionSupport event="onclick" reRender="mainFormId"/>
 </apex:commandButton>
 </apex:pageBlockButtons>
 <apex:pageBlockSection title="Non Recurring Billings" id="NRbill"/> 
<apex:commandButton action="{!NewBillNR}" value="New Non Recurring Billings" immediate="false">
 <apex:param name="type" value="Non Recurring"/>
 </apex:commandButton>
 <apex:pageBlockTable value="{!wrapRecords_NR}" var="Rec">
 <apex:column > <apex:facet name="Action">Action</apex:facet> 
<apex:inputCheckbox value="{!Rec.selected}" id="inputId"/> 
<apex:outputText value="{!Rec.bill.billingLink__c}" escape="false" styleClass="actionLink"/>&nbsp;|&nbsp; <apex:commandLink onclick="return DeleteBill('{!Rec.bill.Id}');" value="Del" id="theCommandLink"/> </apex:column>
 <apex:column > <apex:facet name="header">Description</apex:facet> <apex:outputText value="{!Rec.bill.Name}"></apex:outputText> </apex:column>
 <apex:outputLabel value="{!Rec.bill.Name}" id="RecId" /> <apex:outputLink value="{!Rec.bill.billingLink__c}" >Your Hyperlink Text</apex:outputLink>
 <apex:column > <apex:facet name="header">Billing Amount per Period(USD)</apex:facet> <apex:outputText value="{!Rec.bill.Billing_Amount_Per_Period__c}"/> </apex:column>
 <apex:column headerValue="NTI"> <apex:outputField value="{!Rec.bill.Notification_to_Invoice__c}"/> </apex:column> 
</apex:pageBlockTable> </apex:pageBlock> </apex:form>

 Here is the excerpt from Controller code:

 public PageReference processSelected(){ //We create a new list of Contacts that we be populated only with Contacts if they are selected
 selectedbill = new List<Billing__c>(); 
selListId = new List<String>(); //We will cycle through our list of Non Recurring and and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list 
for(wrapBilling cbill : wrapRecords_NR){
 if(cbill.selected == true)
 { selectedbill.add(cbill.bill);
 selListId.add(cbill.bill.Id); }
 } 
for(wrapBilling cbill: wrapRecords_RecVar){
 if(cbill.selected == true) {
 selectedbill.add(cbill.bill); 
selListId.add(cbill.bill.Id); } 
} // Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
if(selectedbill != null){ System.debug('These are the selected billing records...'); 
for(Billing__c bill: selectedbill) { system.debug(bill); 
system.debug('selListId: '+selListId); } 
if(sendMail()){ for(billing__c bill2Upd : [Select Id,Notification_to_Invoice__c from billing__c where Id in : selListId]){ 
bill2Upd.notification_to_Invoice__c = true ; system.debug('bill2Upd: ' + bill2Upd); update bill2Upd; } 
} 
} // wrapRecords_NR = null; // we need this line if we performed a write operation because getContacts gets a fresh list now 
selectedbill.clear(); 
return null;
 }

 
bob_buzzardbob_buzzard
I think what is happening is that you have a race condition due to defining a command button containing an action support element. What happens when you click the button, in no guaranteed order, is the following:
  • the command button submits the form and executes the processselected action method
  • the action support submits the form, but as it doesn't define an action attribute it simply updates the state of the controller and refreshes the page
Given what you are seeing, it sounds like the action support is the last to fire, which kills the command button postback processing and simply refreshes the page, thus your processselected method is never executed to generate the new list of contacts.

Instead of embeddeding an actionsupport, just use the commandbutton and specific a rerender attribute:
 
<apex:commandButton value="Notification to Invoice" action="{!processSelected}" reRender="mainFormId" />

(I've also removed the immediate="false" attribute, as that is the default behaviour.
Noor FazliNoor Fazli
Thanks bob_buzzard for your response. Actually after trying your code , there is no difference in the behaviour i.e; database update is happening this implies that the controller code is getting executed but the automatic page refresh does not bring the new changes.
 
bob_buzzardbob_buzzard
How do you generate the wrapRecords_NR list?
Noor FazliNoor Fazli
Thanks again bob_buzzard. We have a list control in visual force page with checkbox. Checkbox is used to identify the rows that are selected . So When the button is clicked we have processSelected controller code that builds another list that is used to update the database and after database has been updated we want to display the updated information on visual force page.
bob_buzzardbob_buzzard
Can you post the code for the wrapRecords_NR list?  If that isn't being updated it suggests that the information is cached rather than retrieved afresh.