You need to sign in to do that
Don't have an account?
Visualforce Error : Map key 1011 not found in map
controller class is as
public class demo
{
public map<String,String>demoMap{get;set;}
public List<String> demoList {
get {return new List<String> {'1011','1111','1112','112'};}set;}
public demo()
{
demoMap=new map<String,String>();
demoList=new list<String>();
}
public boolean demoMethod()
{
demoMap=new map<String,String>();
for(String s :demoList )
{
String key=s;
String value='test';
demoMap.put(key,value);
}
return true;
}
}
visualforce page is as
<apex:page controller="demo"> <apex:panelGrid columns="4"> <apex:outputLabel value="{!demoMap[demoList[0]]}"/> <apex:outputLabel value="{!demoMap[demoList[1]]}"/> <apex:outputLabel value="{!demoMap[demoList[2]]}"/> <apex:outputLabel value="{!demoMap[demoList[3]]}"/> </apex:panelGrid> </apex:page>
demoMethod() is not ebign called, so demoMap doesnt contain data, call it in constructor, I dint undertsand why demoMethod() return type is boolean.
public class demo
{
public map<String,String>demoMap{get;set;}
public List<String> demoList {
get {return new List<String> {'1011','1111','1112','112'};}set;}
public demo()
{
demoMap=new map<String,String>();
demoList=new list<String>();
demoMethod(); /*************************call method here ******************/
}
public boolean demoMethod()
{
demoMap=new map<String,String>();
system.debug('*********************** '+demoList);
for(String s :demoList)
{
String key=s;
String value='test';
demoMap.put(key,value);
}
return true;
}
}
Thanks path2cloud.
The most important is sequence of expression in constructor.
eg.
public demo()
{
demoMap=new map<String,String>();
demoList=new list<String>();
demoMethod(); /*************************call method here ******************/
}
in above example.