0

Snippet from the controller and map sample data is below. I am having issue getting to the elements within the map using apex repeat.

I thought I would be able to do {!getAllOptions[tab].tabname} but that gives me Unknown Property 'OptionsController.Tab.tabname'.

Example image of what !getAllOptions[tab] returns:

getAllOptionstab

My desired output of map below is:

Product
ABC 333
AGD 4444
Geometric
ASD 333
FWS 333

Below is the snippet from my controller. I also included my VFP code.

{1=Tab:[options={1=Option:[optdesc=333, udcdesc=ABC], 2=Option:[optdesc=4444, udcdesc=AGD]}, tabname=Product], 2=Tab:[options={1=Option:[optdesc=333, udcdesc=ASD], 2=Option:[optdesc=333, udcdesc=FWS]}, tabname=Geometric]}

public class Tab{
        String tabname {get; private set;}
        Map<Decimal,Option> options {get; private set;}
    }
    
    public class Option{
        String optdesc {get; private set;}
        String udcdesc {get; private set;}
    }
    
    public Map<Decimal,Tab> getAllOptions {
        get{
            Map<Decimal,Tab> tabs = new Map<Decimal,Tab>();
            
            Tab tab = new Tab();
            tab.tabname='Product';
            
            Map<Decimal,Option> options = new Map<Decimal,Option>();
            
            Option option= new Option();
            option.udcdesc='ABC';
            option.optdesc='333';
            options.put(1,option);
            
            option= new Option();
            option.udcdesc='AGD';
            option.optdesc='4444';
            options.put(2,option);
            
            tab.options = options;
            tabs.put(1,tab);
            
            /* ********* */
            
            tab = new Tab();
            tab.tabname='Geometric';
            
            options = new Map<Decimal,Option>();
            
            option= new Option();
            option.udcdesc='ASD';
            option.optdesc='333';
            options.put(1,option);
            
            option= new Option();
            option.udcdesc='FWS';
            option.optdesc='333';
            options.put(2,option);
            
            tab.options=options;
            tabs.put(2,tab);
            
            /* ********* */
            
            return tabs; 
        }private set;
    }

VFP

<apex:page controller="Optionsv2Controller" standardStylesheets="false">
    <div>  
        <table>
            <apex:repeat value="{!getAllOptions}" var="tab">
                <tr>
                    <td><apex:outputText value="{!getAllOptions[tab].tabname}"></apex:outputText></td>
                </tr>
            </apex:repeat>
        </table>
    </div>
</apex:page>
1
  • 1
    Does adding public help i.e. public String tabname {get; private set;}?
    – Keith C
    Commented Apr 5, 2022 at 16:30

1 Answer 1

2

You need the public modifier on your Tab attributes.

    ...
    public class Tab{
        public String tabname {get; private set;}
        public Map<Decimal,Option> options {get; private set;}
    }
    ...
2
  • Thanks Jan. That was the issue. Any idea how I might access optdesc and udcdesc in the VFP?
    – Wes
    Commented Apr 5, 2022 at 19:17
  • Same idea - add the public modifier to optdesc and udcdesc.
    – Jan J
    Commented Apr 6, 2022 at 0:21

You must log in to answer this question.

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