0

I want to render a specific column based on the some conditions, the first is that a flag should be "TRUE" and the second is that the The ids should be the sames, like that, if a click on a specific row, only that row will be rendered but i get an error and i do not know why ?

Map key null not found in map. Error is in expression: '{!IF(AND(flag_placement,map_condidat_cv[key].Placement__c == IDplacement), TRUE, FALSE)}' in component

Here is my code :

<apex:pageBlockTable value="{!map_condidat_cv}" var="key" style="width:100%" >
     <apex:column  headerValue="Placement" value ="{!map_condidat_cv[key].Placement__r.name}" onclick="showPlacement('{!map_condidat_cv[key].Placement__c}')" rendered= "{!flag_placement == false}"/>
     <apex:column  headerValue="Placement"  rendered="{!IF(AND(flag_placement,map_condidat_cv[key].Placement__c == IDplacement), TRUE, FALSE)}">
     <apex:outputpanel>
              <a href="#myAnchor"> Voir Plus de détail sur le placement </a>
     </apex:outputpanel>
</apex:column>
</apex:pageBlockTable>

Note : IDplacement is an ID passed from the apex controller and i want to make sure that only the row with this ID will react .

8
  • Have you tried to check the key, whether it is NULL or not? Something like this: {!IF(AND(NOT(ISBLANK(key)),flag_placement,map_condidat_cv[key].Placement__c == IDplacement), TRUE, FALSE)} Mar 18, 2016 at 11:32
  • i will try it now Mar 18, 2016 at 11:38
  • no error, but all rows have been rendered as if they all have the same ID Mar 18, 2016 at 11:42
  • 2
    I would suggest avoiding having a null key in the map_condidat_cv i.e. fix the problem in the controller.
    – Keith C
    Mar 18, 2016 at 11:52
  • 1
    i think in your case the value of key is null and not the map_condidat_cv[key].Placement__c. i would make sure the value of key is not null
    – Prady
    Mar 18, 2016 at 13:35

1 Answer 1

1

Although I'm having a hard time believing this, it would appear that somemap[key] expressions can't be used in the rendered= attribute of apex:column -- even if all of the map keys are non-null.

Assuming a map map_condidat_cv of <String,Account> where the key is the account.name and hence the key must be present as account.name is required, then

fails Map key not found in map

<apex:pageBlockTable value="{!map_condidat_cv}" var="key" style="width:100%" > 
 <apex:column  headerValue="Placement" rendered="{!LEFT(map_condidat_cv[key].id,3) = '001'}" > 
    <apex:outputpanel >
          <a href="#myAnchor"> Voir Plus de détail sur le placement {!key}</a>
    </apex:outputpanel>
 </apex:column>
</apex:pageBlockTable>

but move the rendered expression to the apex:outputPanel and it works fine:

<apex:pageBlockTable value="{!map_condidat_cv}" var="key" style="width:100%" >
 <apex:column  headerValue="Placement" > 
    <apex:outputpanel rendered="{!LEFT(map_condidat_cv[key].id,3) = '001'}" >
          <a href="#myAnchor"> Voir Plus de détail sur le placement {!key}</a>
    </apex:outputpanel>
 </apex:column>
</apex:pageBlockTable>

You are going to have to rethink how to handle the column render, perhaps by using a wrapper class in the controller with a Boolean getter on each element isVis.

some somewhat-related answers with VF map keys here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .