Visualforce Page:
<apex:page controller="picklistcls3">
<apex:form >
<apex:pageBlock >
<apex:actionFunction name="getitem" action="{!show}" reRender="out" status="stat"/>
<apex:selectList value="{!selected}" size="1" onchange="getitem()">
<apex:selectOptions value="{!items}"/>
</apex:selectList>
<apex:outputpanel id="out">
<apex:actionStatus id="stat">
<apex:facet name="start">
<apex:image value="{!$Resource.loading}"/>
</apex:facet>
<apex:facet name="stop">
<apex:selectList value="{!conselect}" size="1" disabled="{!bool}">
<apex:selectOptions value="{!conitems}"/>
</apex:selectList>
</apex:facet>
</apex:actionStatus>
</apex:outputpanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Class:
public with sharing class picklistcls3 {
public boolean bool { get; set; }
public List<selectoption> conitems { get; set; }
public String conselect { get; set; }
public List<selectoption> items { get; set; }
public String selected { get; set; }
public picklistcls3(){
bool=true;
items=new List<selectoption>();
items.add(new selectoption('','--Select an Account--'));
/*items.add(new selectoption('1','a'));
items.add(new selectoption('2','b'));
items.add(new selectoption('3','c'));
items.add(new selectoption('4','d'));*/
List<Account> lstacc= [select id,name from Account];
for(account a:lstacc){
items.add(new selectoption(a.id,a.name));
}
}
public PageReference show() {
bool=false;
conitems=new List<selectoption>();
List<contact> lstcon=[select id,name from contact where accountid=:selected];
for(contact c:lstcon){
conitems.add(new selectoption(c.id,c.name));
}
return null;
}
}
No comments:
Post a Comment