pass value from vf page to controller code example

Example 1: how to pass values from vf page to controller

<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>

Example 2: how to pass values from vf page to controller

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;    }}

Tags:

Misc Example