Sei sulla pagina 1di 5

319-21 Apex Methods In VF

=============================
​ Intrest Calculator
=============================

class
--------------------------------------------------
public class Intrest_Calculator {
public Decimal amount {set;get;}
public Integer years {set;get;}
public Integer rate {set;get;}
public Decimal intrest {set;get;}

public void callMe(){


intrest=(amount*rate*years)/100;
}

public void cancel(){


amount=null;
years=null;
rate=null;
intrest=null;
}

Vf page
------------------------------------------------------------
<apex:page controller="Intrest_Calculator">
<apex:sectionHeader title="Intrest" subtitle="Calculator" help="/apex/abhi1" />
<apex:form >
<apex:pageBlock title="Intrest" >
<apex:pageBlockButtons location="Bottom" >
<apex:commandButton value="Submit" action="{!callMe}" reRender="pbs" />
<apex:commandButton value="Cancel" action="{!cancel}" reRender="pbs" />
</apex:pageBlockButtons>

<apex:pageBlockSection columns="1" id="pbs" >


<apex:pageBlockSectionItem >
Amount:<apex:inputText value="{!amount}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Rate:<apex:inputText value="{!rate}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Years:<apex:inputText value="{!years}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Intrest:<apex:outputText value="{!intrest}" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>

</apex:pageBlock>
</apex:form>
</apex:page>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PickList Example :

class
--------------------------------------------------------------
public class PickList_Example {
public string myValue {set;get;}
public string newValue {set;get;}

public void execute(){


newValue='You have selected :'+myValue;
}
}

Vf Page
--------------------------------------------------------------------------------------------------------------------------------------

<apex:page controller="PickList_Example" >


<apex:form >
<apex:selectList size="1" value="{!myValue}" >
<apex:selectOption itemLabel="-None-" itemValue="None" />
<apex:selectOption itemLabel="Orai" itemValue="UP" />
<apex:selectOption itemLabel="Jhanshi" itemValue="Bundelkhand" />
<apex:selectOption itemLabel="Gwalior" itemValue="MP" />
</apex:selectList>

<apex:commandButton value="submit" action="{!execute}" />


<br/><br/>
<apex:outputLabel value="{!newValue}"/>
</apex:form>
</apex:page>
-------------------------------------------------------------------------------------------------------------------------------------------
RenderedExample
class
----------------------------------------------------------------------------

public class RenderedExample {


public string selected {set;get;}
public Integer count {set;get;}

public void invoke(){


if(selected=='Account'){
count=1;
}
else if(selected=='Contact'){
count=2;
}
else if(selected=='Opportunity'){
count=3;
}
else{
count=0;
}

}
}
Vf page
----------------------------------------------------------------------------------------------------------------------------------------------------
<apex:page controller="RenderedExample" >
<apex:form >
<apex:pageBlock id="pb" >
<apex:selectList size="1" value="{!selected}" >
<apex:selectOption itemLabel="-None-" itemValue="None" />
<apex:selectOption itemLabel="Account" itemValue="Account" />
<apex:selectOption itemLabel="Contact" itemValue="Contact" />
<apex:selectOption itemLabel="Opportunity" itemValue="Opportunity" />
</apex:selectList>

<apex:commandButton value="Go" action="{!invoke}" reRender="pb" />

<apex:pageBlockSection title="Account" collapsible="false" rendered="{!count==1}" >


Account Name:
<br/><br/>
Account Phone:
</apex:pageBlockSection>
<apex:pageBlockSection title="Contact" collapsible="false" rendered="{!count==2}">
Contact Name:
<br/><br/>
Contact Phone:
</apex:pageBlockSection>
<apex:pageBlockSection title="Opportunity" collapsible="false" rendered="{!count==3}" >
Opportunity Name:
<br/><br/>
Opportunity Phone:
</apex:pageBlockSection>
</apex:pageBlock>

</apex:form>
</apex:page>
-------------------------------------------------------------------------------------------------------------------------------------------------------
​Loan Example
class
---------------------------------------------------------------------

public class Loan {


public string selected {set;get;}
public Integer count {set;get;}

public void invoke(){


if(selected =='Education'){
count=1;
}
else if(selected =='Housing'){
count=2;
}
else{
count=0;
}
}
}

Vf Page
---------------------------------------------------------------------------------------------------------------------------------------------------

<apex:page controller="Loan" >


<apex:form>
Application Type:&nbsp;&nbsp;
<apex:selectList size="1" value="{!selected}" >
<apex:selectOption itemLabel="-None-" itemValue="None" />
<apex:selectOption itemLabel="Education" itemValue="Education" />
<apex:selectOption itemLabel="Housing" itemValue="Housing" />
</apex:selectList>

<apex:commandButton value="Go" action="{!invoke}" reRender="pb" />


<apex:pageBlock title="Application" id="pb" >

<apex:pageBlockSection title="Coustomer details" collapsible="false" columns="2" >


<apex:pageBlockSectionItem>
Name:<apex:inputText />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem>
Phone:<apex:inputText />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem>
First Name:<apex:inputText />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem>
Email:<apex:inputText />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection title="Education details" collapsible="false" columns="2" rendered="{!count==1}">
<apex:pageBlockSectionItem>
Qualification:<apex:inputText />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem>
University:<apex:inputText />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem>
Year:<apex:inputText />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem>
Grade:<apex:inputText />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection title="Property details" collapsible="false" columns="2" rendered="{!count==2}" >
<apex:pageBlockSectionItem>
Type:<apex:inputText />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem>
Cost:<apex:inputText />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem>
Area:<apex:inputText />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem>
Location:<apex:inputText />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
------------------------------------------------------------------------------------------------------------------------------------------------------------------

Potrebbero piacerti anche