Saturday, 26 May 2012

To perform arithmetic operations (VF)


<apex:page sidebar="false" controller="arthematic">
<!-- We should create form for inserting data into the text fields-->
<apex:form >
<!-- value atrribure in inputtext is used to set and get the values i.e date enterd in inputbox to controller & controller to vf page-->
<b>Enter value1:</b>&nbsp;&nbsp;<apex:inputText value="{!num1}"/><br/><br/>
<b>Enter value2:</b>&nbsp;&nbsp;<apex:inputText value="{!num2}"/><br/><br/>
<!--commandButton is used to create the button-->
<apex:commandButton value="Sum"/>&nbsp;
<!-- outputText to show the output-->
<apex:outputText value="{!sum}"/><br/><br/>
<apex:commandButton value="Diff"/>&nbsp;
<apex:outputText value="{!diff}"/><br/><br/>
<apex:commandButton value="Mul"/>&nbsp;
<apex:outputText value="{!mul}"/><br/><br/>
</apex:form>
</apex:page>




**************
**************

To perform arithmetic operations (APEX)



public class arthematic { 
   
    public Integer num1 { get; set; }

    public Integer num2 { get; set; }
   
    public Integer sum { set; }//If we take inputbox then only we need this, if use outputtext this datamember is not required
   
    public Integer diff { set; }
   
    public Integer mul { set; }
   
    public Integer div { set; }    
  
    public PageReference addition() {
   
        //return null;
        return Page.arthematic;
    }
   
    public arthematic() {
        num1 = num2 = 0;       
    }   
   
   //Addition
    public Integer getSum() {
        //return num1 + num2;       
        return add();
    }   
    public Integer add() {       
        return num1 + num2;
    }
   
    //Subtraction
    public Integer getDiff() {
        //return num1 + num2;       
        return diff();
    }   
    public Integer diff() {       
        return num1 - num2;
    }
   
    //Multiplication
    public Integer getMul() {
        //return num1 + num2;       
        return mul();
    }   
    public Integer mul() {       
        return num1 * num2;
    }
   
    //Division
    public Integer getDiv() {
        //return num1 + num2;       
        return div();
    }   
    public Integer div() {       
        return num1 / num2;
    }/*//<apex:commandButton value="div"/>
//<apex:outputText value="{!div}"/><br></br><br></br>*/ //Getting Exception
   
    }

***********
***********

Visual Force Basic code



<apex:page >
  <!-- Begin Default Content REMOVE THIS -->
  <h1>Congratulations</h1>
  This is your new Page
  <!-- End Default Content REMOVE THIS -->
</apex:page>


***************************************************



<apex:page showHeader="True" sidebar="False" tabStyle="Student__c">
  <!-- showHeader is to enable or disable the Heading part of the Page -->
  <!-- sidebar is to enable or disable the sidebar of the Page -->
  <h1>Welcome to {!$User.Username} Page!</h1>
    <!--    {!} is used to display the dynamic content of the page -->
    <!-- To create a seperate page block -->
  <apex:pageBlock title="Primary" tabStyle="Project__c" >
   <apex:pageBlockSection >
   <h2>Page block section One </h2>
    <apex:pageBlockSectionItem >Srinu</apex:pageBlockSectionItem>
    <apex:pageBlockSectionItem >Somu</apex:pageBlockSectionItem>
    <apex:pageBlockSectionItem >Vasu</apex:pageBlockSectionItem>
    <apex:pageBlockSectionItem >Gopi</apex:pageBlockSectionItem>
   </apex:pageBlockSection>
   <h2>Page block section Two </h2>
   <apex:pageBlockSection >
    <apex:pageBlockSectionItem >Srinu</apex:pageBlockSectionItem>
    <apex:pageBlockSectionItem >Somu</apex:pageBlockSectionItem>
    <apex:pageBlockSectionItem >Vasu</apex:pageBlockSectionItem>
    <apex:pageBlockSectionItem >Gopi</apex:pageBlockSectionItem>
   </apex:pageBlockSection> 
  </apex:pageBlock>
    
  <apex:pageBlock title="Secondary" >My Second Block</apex:pageBlock>
  <apex:pageBlock title="Third" tabStyle="Project__c" >My Third Block</apex:pageBlock>
    <h1>Welcome to Srinu Page</h1>
 
  <!-- End Default Content REMOVE THIS -->
</apex:page>

Labels