+ Start a Discussion
DCSDCS 

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="{!r.id}" assignTo="{!eventId}"/>
                    </apex:commandButton>    

 

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.

 

thangasan@yahoothangasan@yahoo

Hai

 

  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}"/>
</apex:commandButton>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

</apex:page>

 

Regards

Thanga

DCSDCS

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.

WesNolte__cWesNolte__c

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.

 

Wes

DCSDCS
Thanks Wes! I ended up doing this way.
PRIYANKA K2PRIYANKA K2
can we pass object like Id in commandLink ?