It is possible to do this, you will need to have a function in your controller which is called by your button. This function can then call the Apex Class function.
You can call a class from a Visual force page button like this:
public pageReference saveItem(){ // Some code goes here }
public pageReference cancelAction(){ // Some code goes here }
public pageReference myaction(){ // Some code goes here } }
The commandbutton attribute, action="{!saveItem}" it refers the save method in the controller and the attribute value="Save" is the text displayed on the commandButton as button label.
It is possible to do this, you will need to have a function in your controller which is called by your button. This function can then call the Apex Class function.
You can call a class from a Visual force page button like this:
public pageReference saveItem(){ // Some code goes here }
public pageReference cancelAction(){ // Some code goes here }
public pageReference myaction(){ // Some code goes here } }
The commandbutton attribute, action="{!saveItem}" it refers the save method in the controller and the attribute value="Save" is the text displayed on the commandButton as button label.
You can call a class from a Visual force page button like this:
Example :
Visual force Page code :
<apex:page controller="myController">
<apex:commandbutton action="{!saveItem}" value="Save"></apex:commandbutton>
<apex:commandbutton action="{!cancelAction}" value="Cancel"></apex:commandbutton>
<apex:commandButton action="{!myAction}" value="myaction"></apex:commandbutton>
</apex:page>
Apex Class code:
public class myController{
public pageReference saveItem(){
// Some code goes here
}
public pageReference cancelAction(){
// Some code goes here
}
public pageReference myaction(){
// Some code goes here
}
}
The commandbutton attribute, action="{!saveItem}" it refers the save method in the controller and the attribute value="Save" is the text displayed on the commandButton as button label.
All Answers
some thig like this <apex:commandButton action="{!doThis}" value="Save" id="theButton"/> doThis is the method
In order to call a method in a class that should be used as a value in controller or extensions attribute in apex:page component
You can call a class from a Visual force page button like this:
Example :
Visual force Page code :
<apex:page controller="myController">
<apex:commandbutton action="{!saveItem}" value="Save"></apex:commandbutton>
<apex:commandbutton action="{!cancelAction}" value="Cancel"></apex:commandbutton>
<apex:commandButton action="{!myAction}" value="myaction"></apex:commandbutton>
</apex:page>
Apex Class code:
public class myController{
public pageReference saveItem(){
// Some code goes here
}
public pageReference cancelAction(){
// Some code goes here
}
public pageReference myaction(){
// Some code goes here
}
}
The commandbutton attribute, action="{!saveItem}" it refers the save method in the controller and the attribute value="Save" is the text displayed on the commandButton as button label.