function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Arun KharbArun Kharb 

Binding the values of a Map on VF page dynamically not working

Hi All,
I have a page in which I am rendering various fields of different datatype based on some condition.

User-added image 
Here is the controller code for this.
public Map<String,String> finalselectedvalues{get;set;}
public map<String,List<SelectOption>> dataarraymap{get;set;}
public List<Objectname> lstProducts{get;set;}

public demoController() {

 finalselectedvalues=new Map<String,String>();
 dataarraymap=new Map<String,List<SelectOption>>();
SelectedValues=new Map<String,String>();
lstProducts=[//query to get values];
 lst.add(new SelectOption('Default','----none---- '));
 dataarraymap.put(String.valueof(obj.name),lst);

for(objectname obj:lstProducts)
{
     if(obj.Attribute_Type__c=='Heading' || obj.Attribute_Type__c=='State Coverage') //many more condition goes here
            {  
                 List<selectOption> lst=new List<selectOption>();
                 lst.add(new SelectOption('Default','----none---- '));
                 dataarraymap.put(String.valueof(obj.name),lst);
           }
        finalselectedvalues.put(obj.name,' ');
}
}
and in vf page i am rendering different type of input fields like this:
<apex:repeat id="dvProducts" value="{!lstProducts}" var="product">
  <apex:outputPanel rendered="{!IF(product.Attribute_Type__c=='State Coverage',TRUE,FALSE)}" >
     <apex:selectList value="{!finalselectedvalues[product.name]}" size="3"  multiselect="true" > 
      <apex:selectOptions value="{!dataarraymap[product.name]}" /> 
     </apex:selectList>
  </apex:outputPanel> 
</apex:repeat>
 
Now, Whenever I am trying to submit the page without filling up any value in selectlist, radiobutton and many more types excluding text Input Type. I am getting following error:
 
Map key {{keyvalue}} not found in map 

Error is in expression '{!finalselectedvalues[key]}'

and If I fill out all the values like select something in select list and check all radio buttons then No Error is thrown. I am not even Using  REQUIRED Attribute here. 
 
Any Help would be very much appreciated.

 
logontokartiklogontokartik
Hi Arun,

There might be issue with your map not having a specific value and trying to get that value is causing your the error. I am not sure if this is complete code, but assuming you are using finalSelectedValue only in one place. try doing this in your page 
 
<apex:outputPanel rendered="{!IF(product.Attribute_Type__c=='State Coverage',TRUE,FALSE) && (product.name != null)}" >

<apex:selectList value="{!finalselectedvalues[product.name]}" size="3"  multiselect="true" >        <apex:selectOptions value="{!dataarraymap[product.name]}" />  </apex:selectList>




 
Arun KharbArun Kharb
Hi Kartik,
I have tried printing them in debug as well as on VF page and all are returning the required output.
Arun KharbArun Kharb
yes, this is not the complete code there are lot of fields which are rendering based on the condition. and if this would be the problem them how it can  work when i select a value from select list and radio buttons instead of leaving them as unselected as mentioned in the image above. It