You need to sign in to do that
Don't have an account?
Mahesh Babu Ravella
Multiple command buttons in a page not working
Hi,
I have tried to implement the simple operations such as Add, Subtract, Multiply and Divide through callouts. So my page has 4 buttons.
But only the first button click works fine and gives me the result. When i try to fire another event, it doesn't work. Below are my controller and Visualforce page.
Please help !!
Controller:
public class CalculatorController{
public double a;
public double b;
public double c;
public final wwwParasoftComWsdlCalculator.ICalculator calculator;
public CalculatorController(){
calculator = new wwwParasoftComWsdlCalculator.ICalculator();
}
public double getA(){
return a;
}
public void setA(double number1){
a = number1;
}
public double getB(){
return b;
}
public void setB(double number2){
b = number2;
}
public double getC(){
return c;
}
public void setC(double number2){
c = number2;
}
public void Add(){
System.debug(a);
System.debug(b);
c = calculator.add(a,b);
}
public void Subtract(){
System.debug(a);
System.debug(b);
c = calculator.subtract(a,b);
}
public void Divide(){
System.debug(a);
System.debug(b);
c = calculator.divide(a,b);
}
public void Multiply(){
System.debug(a);
System.debug(b);
c = calculator.multiply(a,b);
}
}
Visualforce page:
<apex:page controller="CalculatorController" sidebar="false">
<apex:form >
<apex:pageBlock title="Calculator">
<apex:pageBlockSection title="Inputs" collapsible="false">
<apex:inputText label="Number 1" value="{!a}" title="Number 1"/>
<apex:inputText label="Number 2" value="{!b}" title="Number 2"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Result" columns="1" collapsible="false">
<apex:inputText label="Result" value="{!c}" title="Result" disabled="true"/>
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!Add}" value="Add"/>
<apex:commandButton action="{!Subtract}" value="Subtract"/>
<apex:commandButton action="{!Multiply}" value="Multiply"/>
<apex:commandButton action="{!Divide}" value="Divide"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
I have tried to implement the simple operations such as Add, Subtract, Multiply and Divide through callouts. So my page has 4 buttons.
But only the first button click works fine and gives me the result. When i try to fire another event, it doesn't work. Below are my controller and Visualforce page.
Please help !!
Controller:
public class CalculatorController{
public double a;
public double b;
public double c;
public final wwwParasoftComWsdlCalculator.ICalculator calculator;
public CalculatorController(){
calculator = new wwwParasoftComWsdlCalculator.ICalculator();
}
public double getA(){
return a;
}
public void setA(double number1){
a = number1;
}
public double getB(){
return b;
}
public void setB(double number2){
b = number2;
}
public double getC(){
return c;
}
public void setC(double number2){
c = number2;
}
public void Add(){
System.debug(a);
System.debug(b);
c = calculator.add(a,b);
}
public void Subtract(){
System.debug(a);
System.debug(b);
c = calculator.subtract(a,b);
}
public void Divide(){
System.debug(a);
System.debug(b);
c = calculator.divide(a,b);
}
public void Multiply(){
System.debug(a);
System.debug(b);
c = calculator.multiply(a,b);
}
}
<apex:page controller="CalculatorController" sidebar="false">
<apex:form >
<apex:pageBlock title="Calculator">
<apex:pageBlockSection title="Inputs" collapsible="false">
<apex:inputText label="Number 1" value="{!a}" title="Number 1"/>
<apex:inputText label="Number 2" value="{!b}" title="Number 2"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Result" columns="1" collapsible="false">
<apex:inputText label="Result" value="{!c}" title="Result" disabled="true"/>
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!Add}" value="Add"/>
<apex:commandButton action="{!Subtract}" value="Subtract"/>
<apex:commandButton action="{!Multiply}" value="Multiply"/>
<apex:commandButton action="{!Divide}" value="Divide"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
You have to rerender the form after each action.
First step add an Id to your form <Form id="test">
second add rerender attribut to all your buttons like below
<apex:commandButton action="{!Add}" value="Add" rerender="test"/>
Cheers
I have tried that but it's not working.
I see from the logs that the method itself is not being called.
Thanks !!.