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
Bob NagyBob Nagy 

2 days, no luck, need help with apex:inputfield checkbox not displaying proper value

I have a visualforce page that includes a pageBlockTable that has one readonly text column and 6 inputField columns (sort of like a spreadsheet).  The method associated with the value attribute of the pageBlockTable (getStageSpecificSCSettings()) passes the table a list of custom objects and the table is used to edit those objects. The problem is that 2 of the columns are checkbox fields and the initial display of the page shows those checkboxes checked even though the value in the field in the database is unchecked (false).  What's crazy is there is another column that is also an inputField of a checkbox field and it, along with the 3 text fields display the proper state of the checkbox.

Now you are probably thinking that I forgot to include the to misbehaving fields in the query of the records to be supplied to the data table but that's not it - I checked about a hundred times.  In fact, I put debug statements to inspect the state of the checkboes in the list of objects just before the collection is sent to the data table and the values in the objects are reflective of their state in the database (and the same value displayed on the View version of this same page).

If that is not wired enough, I have other logic on the page that if you click option button A the page rerenders and the data table is hidden.  If you click on option button B the page redisplays and the data table is displayed again and this time the value are correct!

There is NO immediate="true" anywhere on the page as I have seen references to that causing issues with chechbox rendering.

Here is the section of the VF page that shows the data table.  The "Active" and "Email Alert" columns are the chechbox fields that don't work, the "Chatter Post" column is a checkbox field that does work:
<apex:pageBlockSection columns="1"  >
  <apex:pageBlockTable value="{!StageSpecificSCSettings}" 
                                             var="SCS" id="SettingsList" 
	                                      rowClasses="odd,even" 
                                               styleClass="tableClass" 
                                               rows="100" 
                                                frame="none" >
	                                       
   <apex:column headerValue="Stage" >
	 <apex:outputText value="{!SCS.Opportunity_Stage_Name__c}" />
   </apex:column> 
	                   	                    
   <apex:column headerValue="Active" >
      <apex:inputField value="{!SCS.Active__c}" />
   </apex:column>  
	
   <apex:column headerValue="Email Alert" >
      <apex:inputField value="{!SCS.Send_Email_Alert__c}" />
   </apex:column> 
	                    
   <apex:column headerValue="Chatter Post" >
      <apex:inputField value="{!SCS.Post_Chatter_Alert__c}" />
   </apex:column> 
	                    
   <apex:column headerValue="Setting Value"  >
       <apex:inputField value="{!SCS.Param1_Value__c}" />
    </apex:column> 
	                    
   <apex:column headerValue="Alert Score" >
	<apex:inputField value="{!SCS.Status_Alert_Score__c}" />
   </apex:column> 
	                    
   <apex:column headerValue="Alert Text" >
      <apex:inputField value="{!SCS.Status_Alert_Text__c}"  />
   </apex:column> 
                                               
</apex:pageBlockTable>
</apex:pageBlockSection>
The controller method that supplies the list of custom objects looks like this:
public list<InSituOsm__Status_Check_Setting__c> getStageSpecificSCSettings() 
{	  		 		
 	
	for (InSituOsm__Status_Check_Setting__c s : m_listSCSettings)
	{	 	
		system.debug('+++Check RECORDS: ' + s.Opportunity_Stage_Name__c);
		system.debug('++++++Active  = : ' + s.Active__c); 
		system.debug('++++++Email   = : ' + s.Send_Email_Alert__c);
		system.debug('++++++Chatter = : ' + s.Post_Chatter_Alert__c);
	}
 	
 	return m_listSCSettings;
}
The debug statements confirm that the values in the sObject fields are consistent with the values in the database but when the data table displays them they are NOT correct for the first two checkbox fields but are correctly displayed for the 3rd checkbox field.

I have tried changing the order of the columns, changing the data table to only display one of the checkboxes that is misbehaving, changing the controller method to perform the database query in the method that returns the collection of records rather than the constructor and nothing seems to work.  I did discover that value that is always initially displayed id the default value of the field definition.  Right now the two misbehaving checkboxes always initially display as checked but if I chhange the default value on the fields to Unchecked then the checkboxs initially display as unchecked.

It feels like a SF bug but surley others would be seeing this if it were.  All ideas are welcome - Thanks!


 
Best Answer chosen by Bob Nagy
Bob NagyBob Nagy
After more digging I found the issue.  It is a Known Issue with no fix - W-1467762
What I failed to mention was that due to some logic which was not relevent to the example, or so I thought, the collection of sObjects passed to the data table are actually cloned instances of the records from the datbase but the cloning is done WITHOUT Ids (first paramerter of the clone method set to false).  In my case I don't want objects with Ids but without them the VF page is rendeing the value of the checkbox with the field definition's default value rather than the value you set on the sObject in the controller.  It especially sucks because this was not a problem before, SF broke it, and no no indication if/when they will fix it.