function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
djfubardjfubar 

Return Apex Page Message when calling get accessor of a property

Hi,

 

Is it possible to return a page message to the visualforce page if an exception occurs on the get accessor os a property?

 

//Apex Code

public String appDate {get; set;}

public List<selectOption> Dates{
get {
return GetDates();
}
set;
}

 

public List<selectOption> GetDates() {

 

try{

 

//do something here

 

}

catch(Exception e)

{

ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,e.getMessage()));

return null;

}

}

 

//VF Page Code

<apex:page sidebar="false" title="Date Selector">
<apex:form >
<apex:pageBlock title="Date Selector" mode="edit">
<apex:pageMessages />
<apex:pageBlockSection title="" columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Dates" for="appDate"/>

<apex:selectList id="results" size="1" value="{!Date}" label="Date" styleClass="select">
<apex:selectOptions value="{!Dates}"/>
</apex:selectList>

</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>