• Mahesh Babu Ravella
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
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>
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>