| 1. |
Access Custom Controller-defined Enum In Custom Component? |
|
Answer» We cannot reference the enum DIRECTLY since the enum itself is not visible to the page and you can’t make it a property. Apex class: global with sharing class My_Controller { public Case currCase {get; SET; } public enum StatusValue {RED, YELLOW, GREEN} public StatusValues getColorStatus() { return StatusValue.RED; //demo code - just return red } } Visualforce page: <apex:image url='stopsign.png' rendered="{!colorStatus == StatusValue.RED}"/> Above code snippet will throw error something like “Save Error: UNKNOWN property‘My_Controller.statusValue’” Resolution: Add below method in Apex CONTROLLER: public String currentStatusValue { get{ return getColorStatus().name(); }} and change Visualforce code to <apex:image url='stopsign.png' rendered="{!currentStatusValue == 'RED'}" /> We cannot reference the enum directly since the enum itself is not visible to the page and you can’t make it a property. Example: Apex class: global with sharing class My_Controller { public Case currCase {get; set; } public enum StatusValue {RED, YELLOW, GREEN} public StatusValues getColorStatus() { return StatusValue.RED; //demo code - just return red } } Visualforce page: <apex:image url='stopsign.png' rendered="{!colorStatus == StatusValue.RED}"/> Above code snippet will throw error something like “Save Error: Unknown property‘My_Controller.statusValue’” Resolution: Add below method in Apex Controller: public String currentStatusValue { get{ return getColorStatus().name(); }} and change Visualforce code to <apex:image url='stopsign.png' rendered="{!currentStatusValue == 'RED'}" /> |
|