Im trying to create a two lists in vf page from the key and values of a map, if i select a key from one list,then the other list should populate the values of that key..Below is the apex class and VF page for the same. Im facing error in this code,could you please help me put..please suggest if we have any other sotions also.Please excuse for bad code indenting... Apex Class
public class mapdepend {
public string mycity {get;set;}
map<string,List<string>> mybranches= new map<string,List<string>>();
public list<selectoption> city{get;set;}
public list<selectoption> branch{get;set;}
public mapdepend(){
list<string> hyd = new list<string>();
hyd.add('SR Nagar');
hyd.add('LB Nagar');
List<string> bang= new list<string>();
bang.add('Ecity');
bang.add('Matahalli');
mybranches.put('hyd',hyd);
mybranches.put('bang',bang);
set<string> keys= mybranches.keyset();
city=new list<selectoption>();
branch=new list<selectoption>();
List<string> my = new list<string>();
my.add('None');
for(string a: keys)
{
selectoption op1= new selectoption(a,a);
city.add(op1);
}
}
public pagereference show()
{
for (mycity : mybranches.keyset())
{
branch.add(mybranches.get(mycity));
}
return null;
}
}
VF page:
<apex:page controller="mapdepend">
<apex:form >
<apex:selectlist value="{!mycity}" size="1">
<apex:selectoptions value="{!city}">
</apex:selectoptions>
<apex:actionsupport event="onchange" action="{!show}" rerender="one"/>
</apex:selectlist>
<apex:selectList size="1" id="one">
<apex:selectOptions value="{!branch}"></apex:selectOptions>
</apex:selectList>
</apex:form>
</apex:page>