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

Display error/success message on a Form, using View State



I found this article describing how View State works. I would like to reproduce the behavior showed in Figure 1


Basically I have a form, with a button.

Once the user clicks on the button, I want to be able to display a message (error or success) on the same page, using a postback


Can anyone share the code I need to add to my page/controlle, to accomplish what is described in Figure 1 in the link above?


Thanks a lot





Here is a simple example, in this i have a simple textbox and a button, on click of this button checkNull method of controller will be invoke and will check whether textbox value is null or not, depending on value it will display message.



<apex:page controller="TestController">



 <apex:inputText value="{!Var}"/>

<apex:commandButton action="{!checkNull}" value="Check Null"/>




/************* Controller ****************/

public class TestController


public String Value{get; set;}

public PageReference checkNull()


 if(Var !=null)

 ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.CONFIRM, 'Success!'));


 ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, 'Input value cannot be null.'));

return null;