• Anurag Bhardwaaj
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

I've got some really nasty formulas I'm building out and had hoped to use apex:variable to make the code more readable.  Problem is it appears that apex:variable doesn't work with apex:pageBlockTable and apex:dataTable.  Specifically the variable takes on the value for last row in every row.  The same effect does not happen with apex:repeat and apex:dataList.

 

Is this a bug or am I doing something wrong here?  I can't find anything in the documentation, but did find this post which has yet to be answered.

 

To see what I mean here's some sample code that illustrates the issues.

 

 

public with sharing class VariableInRepeatTest {

	public List<Integer> intArray { get; set; }
	{ intArray = new Integer[] { 1, 2, 3 }; }
}

 

<apex:page controller="VariableInRepeatTest">
<apex:pageBlock >
	<apex:pageBlockSection title="Variable in Page Block Table">
		<apex:pageBlockTable value="{!intArray}" var="int">
			<apex:variable var="variable" value="{!int}"/>
			<apex:column headerValue="Value" value="{!int}"/>
			<apex:column headerValue="Variable" value="{!variable}"/>
		</apex:pageBlockTable>
	</apex:pageBlockSection>
	<apex:pageBlockSection title="Variable in Repeat">
		<apex:repeat value="{!intArray}" var="int">
			<apex:variable var="variable" value="{!int}"/>
			Value: {!int} | Variable: {!variable}
		</apex:repeat>
	</apex:pageBlockSection>
	<apex:pageBlockSection title="Variable in Data List">
		<apex:dataList value="{!intArray}" var="int">
			<apex:variable var="variable" value="{!int}"/>
			Value: {!int} | Variable: {!variable}
		</apex:dataList>
	</apex:pageBlockSection>
	<apex:pageBlockSection title="Variable in Data Table">
		<apex:dataTable value="{!intArray}" var="int">
			<apex:variable var="variable" value="{!int}"/>
			<apex:column headerValue="Value" value="{!int}"/>
			<apex:column headerValue="Variable" value="{!variable}"/>
		</apex:dataTable>
	</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>