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

Passing Parameters with Commandbutton

I want to pass one parameter when user clicks on a command button.


I tried the following


                   <apex:commandButton action="{!registerForEvent}" value="Register" title="Register">
                        <apex:param name="eventId" value="{!}" assignTo="{!eventId}"/>


It does not work. The eventid value is coming as null in the controller. 


I was searching through the posts and found a few that says that this is a bug and parameters cannot be passed with command button. Some posts say, it works using assignTo attribute and having proper getter and setter methods for the assignTo variable. It is not working for me.


Is it working for anyone? Please let me know.





  You can pass Parameter ,find below small test program

// Controller


public class TestParamController{
    String paramValue;
    String inputValue;
    public TestParamController(){
        this.inputValue = 'Hai';
    public String getParamValue(){
        return paramValue;
    public void setParamValue(String paramValue){
        this.paramValue = paramValue;
    public String getInputValue(){
        return inputValue;
    public void setInputValue(String inputValue){
        this.inputValue = inputValue;
    public void passParam(){
        System.debug('ParamValue :'+ this.paramValue);
// Page
<apex:page controller="TestParamController">

<apex:form >
<apex:pageBlock mode="edit" id="block">
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:commandButton value="Go!" action="{!passParam}" rerender="block" >
<apex:param name="eventId" value="{!inputValue}" assignTo="{!paramValue}"/>






Thanks for posting the code. Your finding is correct and is passing the param in the sample code.


But when you remove rerender attribute from the command button it looses the value.


<apex:commandButton value="Go!" action="{!passParam}"  rerender="block" >

Somehow it is not behaving properly.


If you get a chance please retest and let me know what you find.


This has been a bug for a while now. If you change your commandbutton to a commandlink it will work. You can then style the link to look like a button.



Thanks Wes! I ended up doing this way.
can we pass object like Id in commandLink ?
David Roberts 4David Roberts 4
I found that it works with commandButton but that the name must be specified
<apex:param name="eventId"...

and that reRender is required but the block doesn't actually need to exist.