9

I am trying to show/hide some map markers on an <apex:map> by assigning a boolean value coming from an Apex attribute to the rendered tag. However, I am receiving a compile error on save:

Literal value is required for attribute rendered in in OfficeMap at line 26 column 6

The code:

<apex:mapMarker title="{!office.Name}" position="{!office.geo}" rendered="{!office.isShown}"/>

However, if I decide to put the value as a string, I can compile my Visualforce successfully:

<apex:mapMarker title="{!office.Name}" position="{!office.geo}" rendered="true"/>

Any idea if this is a known bug, or if there's an alternative?

2
  • 2
    Is this for a single office or for a list of offices? If you are displaying a list, an easy workaround might be to generate a filtered list from your controller.
    – dana
    Jul 20, 2016 at 21:42
  • 2
    Sounds like a bug...you can certainly merge in the value for most tags. Looks reproducible on mapMarker in general.
    – Adrian Larson
    Jul 20, 2016 at 21:43

2 Answers 2

0

Definitely a bug. Here's a simple, ugly workaround:

Instead of

<apex:map>
    <apex:mapMarker title="Home Address" rendered="{!hasHomeAddress}"/>
    <apex:mapMarker title="Work Address"/>
</apex:map>

You can do:

<apex:map rendered="{!hasHomeAddress}">
    <apex:mapMarker title="Home Address"/>
    <apex:mapMarker title="Work Address"/>
</apex:map>
<apex:map rendered="{!NOT(hasHomeAddress)}">
    <apex:mapMarker title="Home Address"/>
    <apex:mapMarker title="Work Address"/>
</apex:map>
-1

Rather than changing your application logic as suggested in the comment, an other workaround is using layoutPanel wich does not result in additional HTML if you set the display attribute to 'none'

<apex:outputPanel id="thePanel" layout="none" rendered="{!office.isShown}">
    <apex:mapMarker title="{!office.Name}" position="{!office.geo}" />
</apex:outputPanel>
1
  • 1
    Output panel is not allowed in Apex:map. Dec 21, 2017 at 19:12

You must log in to answer this question.

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