function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NicGallerNicGaller 

InputText inside of DataTable lost on rerender when immediate=true

Hello,

Here is the scenario:
  • I want to edit multiple records on a page inside of a table
  • Most of the edits are done via <apex:inputField> components and those work great
  • I have a few fields that need to be edited with custom controls instead (so I use <apex:inputText> then decorate them with javascript)
  • I have a button for saving the table.  This works great.
  • I have a button at the bottom of the list for adding a new record.  On that button I set immediate=true, since I did not want validation rules to be applied until the user was ready to commit their work.  When they click that button, the <inputField> values are persisted, but the <inputText> values are getting reset.
  • I can set immediate=false on that "add" button and everything appears to work fine, even when some records are incomplete, so maybe I am just misunderstanding what it does?

I set up a simple example with a contact edit page... here is the page, I put an "Add" and an "Add-Immediate" button, the "Add" button works but the "Add-Immediate" resets edited contacts:
<apex:page controller="GridEditController">
    <apex:form >
        <apex:dataTable id="tbl" value="{!contacts}" var="c">                            
            <apex:column value="{!c.Id}"/>
            <apex:column headerValue="Department">
                <apex:inputText value="{!c.Department}"/>
            </apex:column>
        </apex:dataTable>
        <apex:commandButton value="Add" action="{!addToList}" rerender="tbl" immediate="false"/>
        <apex:commandButton value="Add-Immediate" action="{!addToList}" rerender="tbl" immediate="true"/>        
        <apex:commandButton value="Save" action="{!save}" />
    </apex:form>
</apex:page>

and the controller:
public class GridEditController {
    public List<Contact> contacts { get; set; }
    
    public GridEditController(){
        contacts = [select Id, Department from Contact];
    }
    
    public PageReference addToList(){
        contacts.add(new Contact());
        return null;
    }
    
    public PageReference save(){
        upsert contacts;
        return null;
    }
}

I appreciate any insight.
AshwaniAshwani
Hi Nic,

Setting up immediate=true doesn't post back to controller and setters don't work, if you want data to post back you should use <apex:actionreigon>

Simple Example:


<apex:pageBlockSectionItem >
    <apex:outputLabel value="ClienSide" for="client"/>
    <apex:actionRegion>
       <apex:inputField id="client" value="{!object.obj__c}" required="true">
            <apex:actionSupport event="onblur" action="{!RetrieveAccount}" rerender="otherPanel"/>
       </apex:inputField>
    </apex:actionRegion>
</apex:pageBlockSectionItem>