I have a VF page which must display markups conditionnaly. So I use an outputText tag with a "render" condition. At first, the render condition tested a variable directly:
<apex:outputText rendered="{!theObject.Surface__c > 0 }">
It appears that for some instance records of theObject, the field Surface__c is not populated, which leads to a message "The value 'null' is not valid for operator '>'".
So I try to test if the field has been extracted by my SOQL query.
My idea is to use a Boolean get;set; value, and use try-catch structure to test the field presence and set the boolean value to test in the VF code:
<apex:outputText rendered="{!isSurfacePopulated}">
I tried different coding and did not succeed to trap the exception. I finally ended up with the following Apex code:
public Boolean isSurfacePopulated { get; set; }
public MyControllerExtension(ApexPages.StandardController stdController) {
ID objID = stdController.getId();
MyObject theObject = [SELECT Surface__c FROM MyObject WHERE ID = :objID];
try {
isSurfacePopulated = theObject.Surface__c > 0;
system.debug('No Exception triggered');
}
catch( Exception e ) {
system.debug('Exception trapped');
isSurfacePopulated = false;
}
}
Not only I don't trap the exception, but the code doesn't even seem to execute the try block (the debug log doesn't show any of the system.debug() text I specified).
I don't undertstand how that is possible. Do I miss something ?
Thanks