Tuesday, 23 October 2012


Oh how much I love this Apex:Variable

you can use it to do so many things, such as in an Apex:Repeat and tracking which element of the Repeat you are in, so if the user selects an item and you need to send this 1 change back to the controller and identify which item it is in the List object in the controller, you can easily do this using Apex:Variable

<apex:variable value="{!-1}" var="counter">
    <apex:Repeat value="{!zz}" var="x" >
        <apex:variable value="{!counter + 1}" var="counter" />

<apex:pageBlockSection title="" columns="2" >
<apex:pageBlockSectionItem >                  
                               <apex:outputLabel value="{!$}" />

<apex:selectList value="{!x.a__c}" size="1"  >
<apex:SelectOptions value="{!ss}"></apex:SelectOptions>
<apex:actionsupport event="onchange" action="{!ff}" rerender="qq" >
                           <apex:param name="g" assignTo="{!h}" value="{!x.tt__c}" />
<!-- <apex:param name="k" assignTo="{!k}" value="{!x.j__c}" /> -->
<apex:param name="v" assignTo="{!v}" value="{!counter}" />


Or if you use <Apex:Variable value="{!X}" name="val" />

<Apex:outputText >
    <Apex:Param value="{!X}">
<Apex:outputText >

The outputText automatically inherits the param value which is set from the <Apex:Variable>

Here's a real example: This ensures that the outputText value number is displayed with , separated and to 2 decimal places even though the number could be provided to page in a different format

                   <apex:outputPanel >
                   <apex:variable var="tot" value="{!(l.dd__c * l.uu__c)}" />
                   <apex:outputText value="{0, number, ###,###,###,###.00}">
                    <apex:param value="{!l.ppp__c tot}"/>

No comments:

Post a Comment

Note: only a member of this blog may post a comment.