You need to sign in to do that
Don't have an account?
Mike @ BlackTab
Rerender Component Without Clearing Input Data
When a new row is added, the data from the other rows is cleared. How can I keep the previously entered data even if the entire table is rerendered.
Here is the code:
VF:
<apex:page standardController="Projects__c" extensions="addMultipleBurnsController" showHeader="true" sidebar="true"> <apex:pageBlock title="{!Projects__c.Project_Name__c}" mode="maindetail"> <apex:pageBlockSection title="Project Information"> <apex:outputField value="{!Projects__c.Name}"/> <apex:outputField value="{!Projects__c.Project_Name__c}"/> <apex:outputField value="{!Projects__c.Status__c}"/> <apex:outputField value="{!Projects__c.Start_Date__c}"/> <apex:outputField value="{!Projects__c.Go_Live_Date__c}"/> <apex:outputField value="{!Projects__c.End_Date__c}"/> </apex:pageBlockSection> <apex:pageblocksection title="Project Details"> <apex:outputField value="{!Projects__c.Sold_Hours__c}"/> <apex:outputField value="{!Projects__c.Goal_Hours__c}"/> <apex:outputField value="{!Projects__c.Planned_Hours__c}"/> <apex:outputField value="{!Projects__c.Pricing_Method__c}"/> </apex:pageblocksection> </apex:pageBlock> <apex:form > <apex:pageblock title="Add Multiple Burns"> <apex:pageblockButtons > <apex:commandButton value="Save" action="{!save}" rerender="error"/> <apex:commandButton value="Add Row" action="{!addRow}" rerender="table,error" immediate="true"/> <apex:commandButton value="Remove Row" action="{!removeRow}" rerender="table,error" immediate="true"/> </apex:pageblockButtons> <apex:pageBlockTable value="{!burns}" var="a" id="table"> <apex:column headerValue="Burn" width="125px"> <apex:inputField value="{!a.Name}" required="true"/> <apex:inputField value="{!a.Burn_Status__c}"/> </apex:column> <apex:column headerValue="Resources" width="125px"> <apex:inputField value="{!a.Resource_Type__c}"/><br /> <apex:inputField value="{!a.Resource__c}"/> </apex:column> <apex:column headerValue="Dates Start/End" width="125px"> <apex:inputField value="{!a.Start_Date__c}"/><br /> <apex:inputField value="{!a.End_Date__c}"/> </apex:column> <apex:column headerValue="Hours Planned/Type" width="125px"> <apex:inputField value="{!a.Hours_Planned__c}"/><br /> <apex:inputfield value="{!a.General__c}"/> </apex:column> <apex:column headerValue="Details"> <apex:inputField value="{!a.Burn_Details__c}" style="width:95%"/> </apex:column> </apex:pageBlockTable> <p><apex:pagemessages ></apex:pagemessages></p> </apex:pageblock> </apex:form> </apex:page>
Controller:
public class addMultipleBurnsController { //Class Variables public List<burn__c> burns {get; set;} private final projects__c proj; //Project Controller Extension public addMultipleBurnsController(ApexPages.StandardController stdController){ this.proj = (projects__c)stdController.getRecord(); burns = new List<burn__c>(); burn__c theBurn = new burn__c(); theBurn.Project__c = proj.Id; burns.add(theBurn); //burns.add(new burn__c()); } public void addrow() { burn__c theBurn = new burn__c(); theBurn.Project__c = proj.Id; burns.add(theBurn); //burns.add(new burn__c()); } public void removerow(){ Integer i = burns.size(); burns.remove(i-1); } public pageReference save(){ insert burns; PageReference back = new PageReference('/' + proj.Id); back.setRedirect(true); return back; } }
If you remove "immediate=true' from your button, it will commit your data to the variables first, and then add the row. You data should not clear then.
Hope this helps!