Passing parameters from Visualforce page to Apex controller via <apex:param> - El Toro - Find articles about Visualforce, Apex, Force.com and Salesforce in general

Print Preview

Passing parameters from Visualforce page to Apex controller via <apex:param>

To pass parameters from the Visualforce page to the controller, you can use the <apex:param> as demonstrated on this sample... 

<apex:page controller="aaPage52">
    <apex:form id="RID">
        <apex:commandButton value="click" action="{!TestX}" rerender="RID">
            <apex:param name="X" value="{!X + 1}" />
        </apex:commandButton>
        <apex:outputText value="{!X}"/><br/>

        <apex:commandButton value="click" action="{!TestX2}" rerender="RID">
            <apex:param assignTo="{!X2}" value="{!X2 + 1}" />
        </apex:commandButton>
        <apex:outputText value="{!X2}"/><br/>

    </apex:form>
</apex:page>

public class aaPage52 {
    public Integer X { get; set; }
    public Integer X2 { get; set; }
    
    public aaPage52() {
        X = 0;
        X2 = 0;
    }
    public PageReference TestX() {
        String strX = ApexPages.currentPage().getParameters().get('X');
        if (strX != null) {
            this.X = Integer.ValueOf(strX);
        }
        return null;
    }
    public PageReference TestX2() {
        return null;
    }
}

comments powered by Disqus

© El Toro . IT @ 2013
Andrés Pérez