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
devfyadevfya 

Can I use <apex:message> without an sObject?

Please see my code:

public class MyCustomController {
  public String MyVal { get; set; }
  public void save() {
    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'MyVal: '+MyVal));
  }
}

<apex:page controller="MyCustomController">
  <apex:messages />
  <apex:form >
    <apex:inputText id="textMyVal" value="{!MyVal}" />
    <apex:message for="textMyVal"/>
    <apex:commandButton action="{!save}" value="Save" />
  </apex:form>
</apex:page>

Question:
I know I can use <apex:messages> or <apex:pageMessages>.
But is there a way to display my message in <apex:message for="textMyVal"/>? Can <apex:message> be used without an sObject?

 

Thanks!