This will be super example to understand lightning basics interms of getters, setters and rendering partial page options, I'am sure this code will solve lot of doubts that new bees has.
Compare vf code and lightning code which I have provided below and execute in your org..
You will get much more confidence on lightning
------------------------------------------------------------------------------------------------------------------------
Component code
------------------------------------------------------------------------------------------------------------------------
<aura:component >
<aura:attribute name="num1" type="Integer"/>
<aura:attribute name="num2" type="Integer"/>
<aura:attribute name="num3" type="Integer"/>
<ui:inputNumber label="Number 1" value="{!v.num1}" />
<ui:inputNumber label="Number 2" value="{!v.num2}" />
<aura:attribute name="addbo1" type="Boolean" default="false"/>
<aura:attribute name="subbo1" type="Boolean" default="false"/>
<aura:attribute name="mulbo1" type="Boolean" default="false"/>
<aura:attribute name="divbo1" type="Boolean" default="false"/>
<aura:attribute name="refreshbo1" type="Boolean" default="false"/>
<aura:if isTrue="{!v.addbo1}">
Addition of Two Numbers is : {!num3}
<ui:outputNumber value="{!v.num3}"/>
</aura:if>
<aura:if isTrue="{!v.subbo1}">
Substraction of Two Numbers is : {!num3}
<ui:outputNumber value="{!v.num3}"/>
</aura:if>
<aura:if isTrue="{!v.mulbo1}">
multiplication of Two Numbers is : {!num3}
<ui:outputNumber value="{!v.num3}"/>
</aura:if>
<aura:if isTrue="{!v.divbo1}">
Division of Two Numbers is : {!num3}
<ui:outputNumber value="{!v.num3}"/>
</aura:if>
<ui:button press="{!c.Add}" label="Addition" />
<aura:if isTrue="{!v.refreshbo1}">
<ui:button press="{!c.Refresh}" label="Refresh" />
</aura:if>
<ui:button press="{!c.Sub}" label="Substraction" />
<ui:button press="{!c.Mul}" label="Multiplication" />
<ui:button press="{!c.Div}" label="Division" />
</aura:component>
-----------------------------------------------------------------------------------------------------------------------
Controller code
------------------------------------------------------------------------------------------------------------------------
({
Add : function(component, event, helper) {
var num1=component.get("v.num1");
var num2=component.get("v.num2");
var num3=num1+num2;
component.set("v.num3", num3);
component.set("v.addbo1", true);
component.set("v.refreshbo1", true);
component.set("v.mulbo1", false);
component.set("v.subbo1", false);
component.set("v.divbo1", false);
},
Mul : function(component, event, helper) {
var num1=component.get("v.num1");
var num2=component.get("v.num2");
var num3=num1*num2;
component.set("v.num3", num3);
component.set("v.mulbo1", true);
component.set("v.refreshbo1", true);
component.set("v.divbo1", false);
component.set("v.subbo1", false);
component.set("v.addbo1", false);
},
Sub : function(component, event, helper) {
var num1=component.get("v.num1");
var num2=component.get("v.num2");
var num3=num1-num2;
component.set("v.num3", num3);
component.set("v.subbo1", true);
component.set("v.refreshbo1", true);
component.set("v.mulbo1", false);
component.set("v.divbo1", false);
component.set("v.addbo1", false);
},
Div : function(component, event, helper) {
var num1=component.get("v.num1");
var num2=component.get("v.num2");
var num3=num1/num2;
component.set("v.num3", num3);
component.set("v.divbo1", true);
component.set("v.refreshbo1", true);
component.set("v.mulbo1", false);
component.set("v.subbo1", false);
component.set("v.addbo1", false);
},
Refresh : function(component, event, helper) {
component.set("v.num1", 0);
component.set("v.num1", 0);
component.set("v.divbo1", false);
component.set("v.mulbo1", false);
component.set("v.subbo1", false);
component.set("v.addbo1", false);
component.set("v.refreshbo1", false);
}
})
-------------------------------------------------------------------------------------------------------------------------
visual force page for the caluclator code with same results as above ligtnening
---------------------------------------------------------------------------------------------------------------------------
<apex:page controller="Calculator">
<apex:form >
<apex:pageBlock title="Simple caluclator">
<apex:pageBlockSection columns="1">
<apex:pageBlockSectionItem >
Please Give First Number<apex:inputText value="{!number1}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Please Give Second Number<apex:inputText value="{!number2}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
Please Provide The Operator <apex:inputText value="{!operator}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="ShowResult" action="{!calculation}" ></apex:commandbutton>
<apex:commandButton value="Refresh" action="{!Refresh}" rendered="{!flag}" ></apex:commandbutton>
</apex:pageBlockButtons>
<apex:pageBlockSection rendered="{!flag}">
<apex:pageblockSectionItem >
Result <apex:outputText value="{!result}" >
</apex:outputText>
</apex:pageblockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
------------------------------------------------------------------------------------------------------------------------
Controller
-------------------------------------------------------------------------------------------------------------------------
public class Calculator
{
public boolean flag { get; set; }
public integer number1{get;set;}
public integer number2{get;set;}
public string operator{get;set;}
public double result{get;set;}
public Calculator()
{
flag=false;
}
public void calculation()
{
flag=true;
if(operator.contains('+'))
result=number1+number2;
if(operator.contains('-'))
result=number1-number2;
if(operator.contains('*'))
result=number1*number2;
if(operator.contains('%'))
result=number1/number2;
}
public void Refresh()
{
flag=false;
number1=null;
number2=null;
operator=null;
}
}