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'

<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 '16 at 11:11
  • @Rimii you need to use ApexPages.addMessage to add the pageMassage in your page.
    – Ratan Paul
    Jun 16 '16 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.