Map Scenario

Scenario: 
Create field dependency using vf page

public class MapEaxmple {
    public Map<String, Account>  accMap{set;get;}
    public List<SelectOption> sp{set;get;}
    public Account accs{set;get;}
    public String selected{set;get;}
    public String result{set;get;}
    public MapEaxmple(){
        accMap=new Map<String, Account>();
        sp=new List<SelectOption>();
        Account a1=new Account(name='emilyn', phone='903030');
        Account a2=new Account(name='aabbcc', phone='78576');
        accMap.put('First', a1);
        accMap.put('Sec', a2);
        Set<String> keys=accMap.keySet();
        for(String s:keys){
            SelectOption sop=new SelectOption(s,s);
            sp.add(sop);
        }
    }
    public void data(){
        accs=accMap.get(selected);  
    } 
    }

<apex:page controller="MapEaxmple">
    <apex:form >
               <apex:pageBlock >
               <apex:pageBlockSection >
               <apex:selectList value="{!selected}" size="1">
                              <apex:selectOptions value="{!sp}"  ></apex:selectOptions>
                    <apex:actionSupport event="onchange" action="{!data}" reRender="one" />
                </apex:selectList>
            </apex:pageBlockSection>
            <apex:pageBlockTable value="{!accs}" var="a" id="one">
                <apex:column headerValue="name" value="{!a.name}" />
                <apex:column headerValue="Phone" value="{!a.phone}" />
           
            </apex:pageBlockTable>
           
        </apex:pageBlock>
    </apex:form>
</apex:page> 


Comments

Post a Comment

Popular posts from this blog

Page Layouts

SOQL Scenario-1