Monday 29 September 2014

Calculating numbers on visualforce


Simple calculations on VFpage


<apex:page controller="calculator" sidebar="false" wizard="true" >
 <apex:form >
  <apex:pageBlock title="Calculator">
  <apex:pageBlockButtons style="color:red">

   <apex:commandButton value="add" action="{!add}"/>
   <apex:commandButton value="sub" action="{!sub}"/>
   <apex:commandButton value="mul" action="{!mul}"/>
    <apex:commandButton value="div" action="{!div}"/>
    </apex:pageBlockButtons>
    <center>
    <apex:panelGrid columns="4" style="color:blue" bgcolor="yellow" cellspacing="50" border="10">
 
                  Number1 : <apex:inputText value="{!number1}"/>
                  Number2 : <apex:inputText value="{!number2}"/>
                  Result  : <apex:inputText value="{!result}"/>
 
   </apex:panelGrid>
   </center>
  </apex:pageBlock>
  </apex:form>
</apex:page>

======================================================================
public class calculator {

    public PageReference div() {
    result = number1/number2;
        return null;
    }


    public PageReference mul() {
    result = number1*number2;
        return null;
    }


    public PageReference sub() {
      result = number1 - number2;
        return null;
    }


    public PageReference add() {
 
       result = number1+number2;
        return null;
    }


    public Integer Number1{get;set;}
    public Integer Number2{get;set;}
    public Integer result{get;set;}

}
====================================================================

No comments:

Post a Comment

Complete Salesforce CPQ training Free videos

Salesforcestart:: We are excited to announce that our YouTube channel, Salesforcestart, is your one-stop-shop for all things Salesforce CPQ!...