+ Start a Discussion
Luffy Carl_opLuffy Carl_op 

Two buttons with one action.

there is a table in my visualforce page, i want to find out my report with two ways, for exmple, there are show all reports and show reports in this month. they both point to one list in controller. so, how can i judge which one clicked?
Anupam RastogiAnupam Rastogi
Hi Luffy,

When you click button on a VF page you can call appropriate action, invoking respective method within the Controller Class. And if your need is to invoke the same method but wish to identify the button from which it is invoked then you can use <apex:param> component.

Example:
VF Page - 
<apex:commandButton action="{! button }" title="Button1" value="Button 1" reRender="pb" >
                	<apex:param name="button1" value="Button 1" />
                </apex:commandButton>
                <apex:commandButton action="{! button }" title="Button2" value="Button 2" reRender="pb" >
                	<apex:param name="button2" value="Button 2" />
                </apex:commandButton>

Controller Code - 
public PageReference button() {
        
        //--- Here you can check which button was clicked and then perform respective action
        buttonName = ApexPages.currentPage().getParameters().get('button1');
        System.debug('Output = ' + butName);
        buttonName = ApexPages.currentPage().getParameters().get('button2');
        System.debug('Output = ' + butName);        
        return null;
    }

Thanks
AR

If the reply was useful and solved your problem then please mark it as best answer.