You need to sign in to do that
Don't have an account?
giorgio70
Display error/success message on a Form, using View State
Hello,
I found this article describing how View State works. I would like to reproduce the behavior showed in Figure 1
http://wiki.developerforce.com/page/An_Introduction_to_Visualforce_View_State
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
Giorgio
Hi,
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.
Example-
<apex:page controller="TestController">
<apex:pageMessages/>
<apex:form>
<apex:inputText value="{!Var}"/>
<apex:commandButton action="{!checkNull}" value="Check Null"/>
</apex:form>
</apex:page>
/************* Controller ****************/
public class TestController
{
public String Value{get; set;}
public PageReference checkNull()
{
if(Var !=null)
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.CONFIRM, 'Success!'));
else
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, 'Input value cannot be null.'));
return null;
}
}