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
Tim__mTim__m 

apex:inlineEditSupport and apex:variable bug

Just spent an hour trying to find out why the inlineEditSupport component wasn't updating my picklist field. The bug can be seen with this...

 

<apex:page standardController="Account" recordSetVar="accounts">
	<apex:form >
		<apex:pageBlock >
			<apex:pageBlockButtons >
				<apex:commandButton id="saveButton" action="{!save}" value="Save" />
				<apex:commandButton id="editButton" action="{!edit}" value="Edit" />
				<apex:commandButton id="cancelButton" action="{!cancel}" value="Cancel" />
			</apex:pageBlockButtons>
			<apex:repeat value="{!accounts}" var="acc" rows="20">
				<apex:variable var="isReadOnly" value="{!acc.myCheckboxField__c}" />
				
				<!-- Name field works just as it should no issues here -->
				<apex:outputField value="{!acc.Name}" rendered="{!isReadOnly}"/>
				
				<!-- Display a label or output field based on a apex:variable -->
				<apex:outputLabel value="{!acc.myPicklistField__c}" rendered="{!NOT(isReadOnly)}"/>
				
				<!-- When you dblClick this field you get the picklist and can change the value
				     but the new value is NOT saved to the db. If you look in syslog you can see
				     the new value never gets back to the server, so the bug is on the client? -->
				<apex:outputField value="{!acc.myPicklistField__c}" rendered="{!isReadOnly}"/>
				
				<apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" />
				<hr/>
			</apex:repeat>
		</apex:pageBlock>
	</apex:form>
</apex:page>



The workaround, don't use an apex:variable in the rendered attribute of the apex:outputField. This works...

 

<apex:page standardController="Account" recordSetVar="accounts">
	<apex:form >
		<apex:pageBlock >
			<apex:pageBlockButtons >
				<apex:commandButton id="saveButton" action="{!save}" value="Save" />
				<apex:commandButton id="editButton" action="{!edit}" value="Edit" />
				<apex:commandButton id="cancelButton" action="{!cancel}" value="Cancel" />
			</apex:pageBlockButtons>
			<apex:repeat value="{!accounts}" var="acc" rows="20">
				
				<apex:outputField value="{!acc.Name}" rendered="{!acc.myCheckboxField__c}"/>
				
				<apex:outputLabel value="{!acc.myPicklistField__c}" rendered="{!NOT(acc.myCheckboxField__c)}"/>
				
				<!-- not using apex:variable works -->
				<apex:outputField value="{!acc.myPicklistField__c}" rendered="{!acc.myCheckboxField__c}"/>
				
				<apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" />
				<hr/>
			</apex:repeat>
		</apex:pageBlock>
	</apex:form>
</apex:page>

 

This was tested on an api ver. 22.0 visualforce page with Firefox 6.0.2. I did not test on other browsers.

aballardaballard

I believe the problem is that apex:variable does not "track" the iterations of the repeat.   I think it ends up always having the value of the first iteration (or maybe the last iteration; I forget which). 

 

 

Tim__mTim__m

No, that isn't the case. For example this works... note that I can use the variable in anything other then a outputField that is bound to a picklist field with an inlineEditSupport in play.

 

<apex:page standardController="Account" recordSetVar="accounts">
	<apex:form >
		<apex:pageBlock >
			<apex:pageBlockButtons >
				<apex:commandButton id="saveButton" action="{!save}" value="Save" />
				<apex:commandButton id="editButton" action="{!edit}" value="Edit" />
				<apex:commandButton id="cancelButton" action="{!cancel}" value="Cancel" />
			</apex:pageBlockButtons>
			<apex:repeat value="{!accounts}" var="acc" rows="20">
				<apex:variable var="isReadOnly" value="{!acc.myCheckboxField__c}" />

				<apex:outputField value="{!acc.Name}" rendered="{!isReadOnly}"/>
				
				<apex:outputLabel value="{!acc.myPicklistField__c}" rendered="{!NOT(isReadOnly)}"/>
				
				<!-- not using apex:variable works -->
				<apex:outputField value="{!acc.myPicklistField__c}" rendered="{!acc.myCheckboxField__c}"/>
				
				<apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" />
				<hr/>
			</apex:repeat>
		</apex:pageBlock>
	</apex:form>
</apex:page>