Show/Hide a particular section of VF Page
This post is part of the previous post. you can check here---
Here I am using the custom controller to achieve this functionality.
Controller--
public class ShowMyContacts
{
public string source {get;set;}
public List<selectOption> sourceValue {get;set;}
public boolean flag {get;set;}
public boolean flag1 {get;set;}
public boolean flag2 {get;set;}
public Contact contact {get;set;}
public ShowMyContacts()
{
flag = false;
flag1 = false;
flag2 = false;
sourceValue = new List<selectOption>();
sourceValue.add(new selectOption('','--select--'));
sourceValue.add(new selectOption('web','Web'));
sourceValue.add(new selectOption('phoneinquiry','Phone Inquiry'));
sourceValue.add(new selectOption('partner','Partner Referral'));
sourceValue.add(new selectOption('other','Others'));
}
public void doSomething()
{
If(source == 'web'){
flag = true;
flag1 = false;
}
else if(source == 'phoneinquiry'){
flag1 = true;
flag = false;
}
else if(source == 'other'){
flag2 = true;
flag = false;
flag1 = false;
}
}
}
VF Page--
<apex:page controller="ShowMyContacts">
<apex:form id="frm" >
<apex:pageBlock >
<center>
<apex:selectList value="{!source}" size="1" >
<apex:selectOptions value="{!sourceValue}" />
<apex:actionSupport event="onchange" action="{!doSomething}" reRender="frm"/>
</apex:selectList>
</center>
</apex:pageBlock>
<apex:pageBlock rendered="{!flag}">
<apex:pageBlockSection >
<apex:inputText value="{!contact.FirstName}" label="FirstName" />
<apex:inputText value="{!contact.Lastname}" label="LastName"/>
<apex:inputText value="{!contact.Title}" label="Title"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock rendered="{!flag1}">
<apex:pageBlockSection >
<apex:inputText value="{!contact.Phone}" label="Phone"/>
<apex:inputText value="{!contact.HomePhone}" label="Home Phone"/>
<apex:inputText value="{!contact.OtherPhone}" label="Other Phone"/>
<apex:inputText value="{!contact.MobilePhone}" label="Mobile Phone"/>
<apex:inputText value="{!contact.AssistantPhone}" label="Ass. Phone"/>
<apex:inputText value="{!contact.Fax}" label="Fax"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock rendered="{!flag2}">
<apex:pageBlockSection >
<apex:inputText value="{!contact.MailingCountry}" label="Mailing Country"/>
<apex:inputText value="{!contact.MailingStreet}" label="Mailing Street"/>
<apex:inputText value="{!contact.MailingCity}" label="Mailing City"/>
<apex:inputText value="{!contact.MailingState}" label="Mailing State"/>
<apex:inputText value="{!contact.OtherStreet}" label="Other Street"/>
<apex:inputText value="{!contact.OtherCity}" label="Other City"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Comments
Post a Comment