• Yakov Veromeev
  • NEWBIE
  • 5 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

I have a map of this structure...

 

private Map<String,List<MyObject__c>> mymap = new Map<String,List<MyObject__c>>();

In order to keep things generic, it is not clear at all, how many string->list pairs there are going to be in the map. Now, if I repeat over one of these lists in a VisualForce page like this...

 

<apex:repeat value="{!mymap['someindex']}" var="el">
</apex:repeat>

 ...how am I going to determine the actual size of mymap['someindex']? Eventually I want to do something as simple as this...

 

<li class="{!IF(count=mymap['someindex'].size,'active','')}">

However, the size method of a list does not seem to work in VisualForce. Anyways, this procedure already seems to require for me to wrap this stuff with a quite redundant count variable like so...

 

<apex:variable var="count" value="{!0}"/>
<apex:repeat value="{!mymap['someindex']}" var="el">
    <apex:variable var="count" value="{!count + 1}"/>
    <li class="{!IF(count=mymap['someindex'].size,'active','')}">
</apex:repeat>

So, how would you do this, because my current solution looks like this and is far from generic at all and - as for my tastes - does not look good at all...

 

<apex:repeat value="{!mymap['myindex']}" var="el">
    <li class="{!IF(el.Property__c=='knownPropertyOfLastElementInList','last','')}">
        ...
    </li>
</apex:repeat>

...or is there a way to declare a getter in my controller that can receive parameters, somewhat like this...

 

<li class="{!IF(count=listlength('mymap','someindex'),'active','')}">

Cheers, Tobias.