I have a requirement where I want a section to render depending on a value of a controller variable. If the section is not rendered I want an error message to be displayed. I have the following piece of code

<apex:pageblock rendered="{!AModel.enableSection}">

I want something like this

if enablesection is true render page block else display String message 'Section cannot be rendered'

1 Answer 1

<apex:pageblock rendered="{!AModel.enableSection}">

<apex:pageMessages rendered="{!NOT(AModel.enableSection)}"/>

Use apexPageMessage with Rendered

And in controller use

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Section cannot be rendered'));
  • How would I pass the static value to the page message? I would not be able to return it form a method
    – Rimii
    Jun 16, 2016 at 11:11
  • @Rimii you need to use ApexPages.addMessage to add the pageMassage in your page.
    – Ratan Paul
    Jun 16, 2016 at 11:12

You must log in to answer this question.

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