You need to sign in to do that
Don't have an account?
Map key null not found in map
Hello all!
So, here's my problem: I have a VF page with a custom controller. Inside the page I'm rendering a Map<String, List<Wrapper>> using 2 repeats, where Wrapper is an inner class built around the OpportunityLineItem object. It looks like this:
public class OpportunityLineItemWrapper { public OpportunityLineItem lineItem {get; set;} public Boolean isSelected {get; set;} public Boolean productHasWSCASelected {get; set;} public Decimal year1Discount {get; set;} public Decimal total {get; set;} public String productName {get; set;} public String productId {get; set;} public OpportunityLineItemWrapper() { lineItem = new OpportunityLineItem(); isSelected = false; productHasWSCASelected = false; year1Discount = 0; total = 0; productName = ''; productId = ''; } }
isSelected is used in the VF page make the whole wrapper record editable or not. It's a checkbox that I'm using to rerender the pageBlock for the map and make some fields editable when checked.
<apex:pageBlock title="test the map null thingie" id="tst"> <table> <apex:repeat value="{!existingLineItemsMap}" var="family" id="repeat"> <tr> <td colspan="15"> {!family} </td> </tr> <apex:repeat value="{!existingLineItemsMap[family]}" var="wrapper" rendered="{!family <> null}"> <tr> <td class="borderClass"> <apex:actionRegion > <apex:inputCheckbox value="{!wrapper.isSelected}"> <apex:actionSupport event="onchange" action="{!recalculateSummaryTable}" reRender="tst" status="status" /> </apex:inputCheckbox> </apex:actionRegion> </td> <td class="borderClass"> <apex:outputLink value="/{!wrapper.productId}" id="theLink" target="_blank" > {!wrapper.productName} </apex:outputLink> </td> </tr> </apex:repeat> </apex:repeat> </table> </apex:pageBlock>
recalculateSummaryTable doesn't modify the map in any way, I've put System.debugs at the begining and at the end of it and the map has the same value.
The problem is when I click in the page one of the checkboxes I'll get an error:
Visualforce Error Map key null not found in map Error is in expression '{!existingLineItemsMap[family]}' in component <apex:page> in page addproductsform2
I really don't get it what null value is it seing. The debugs show a 'good' map...
I'm wrecking my brains for about 2 days on this one :( and I still haven't managed to solve it!!! Any suggestion is highly apreciated if you can help me please.
Thanks,
Adrian
Try to add something in existingLineItemsMap to handle when it returns null,...
Hi Jia Hu,
Thank you for the answer.
I need existingLineItemsMap to keep it's value, I'm using it as a global var so I need to keep the modifications made by the user on it so I can save them when the user will click a button. existingLineItemsMap is initialized through a separate method in the constructor and not through its getter.
What exactly do you mean by "add something in existingLineItemsMap to handle when it returns null"?
Thanks,
Adrian
Map<String, List<Wrapper>> existingLineItemsMap = new Map<String, List<Wrapper>>();
in you code.
And the most frustrating part is that it's not throwing any error in code, I don't have any try/catch block that could catch smth like this, and it's not sending an Apex Warning Mail!!
It's like grasping at straws...
I've added
Still the same error... :(
I'm trying to use the View State to see where the problem is, but after clicking the checkbox and the error shows up there's no View State tab in the Development Mode.
LE: still haven't found what the %^& that error was about, but since I'm constrained by time I've done a workaround... I've replaced the Map<String, List<Wrapper>> with a List<FWrapper>, where FWrapper(another wrapper class) contains both the string and the List of Wrappers from the map. Since I've replaced the Map with the List in the apex:repeat everything has worked fine. :(
Thanks again Jia for the help,
Adrian