public class displayMessage {
public Account Acc{get;set;}
public displayMessage()
{
Acc = new Account();
}
public PageReference Submit() {
if(Acc.Name == null)
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'Please enter name!!!'));
return null;
}
}
Include <apex:pageMessages /> in your vf page and ensure that it is rerender after the method call.
Try this eg:
VF Page
Apex Controller:
Hope this helps...