Difference between multiple messaging components in Visualforce Page
It is used for display a message for a specific component, such as a warning or error.
<apex:message></apex:message>
It is used for display all messages for all components on the current page, such as a warning or error.
<apex:messages></apex:messages>
It is used for displaying custom messages in the visualforce page using the Salesforce pattern for errors, warnings and other types of messages for a given severity.
<apex:pagemessage></apex:pagemessage>
It is used for displays all the messages that were generated for all components on the current visualforce page, presented using the Salesforce styling.
Apex Messages in Salesforce are used for displaying messages such as a warning or an error in visualforce page. In this article I’ll demonstrate how to use different types of messaging options in VisualForce page.
Apex message severities are:
public class SuccessMessage
{
public SuccessMessage()
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.Confirm, 'This is a success message'));
}
}
public class ErrorMessages
{
public ErrorMessages()
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.Error, 'This is an error message'));
}
}
public class WarningMessage
{
public WarningMessage()
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.Warning, 'This is a warning message'));
}
}
public class InfoMessage
{
public InfoMessage()
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.Info, 'This is an informational message'));
}
}
Sometimes we need to disable right click on visualforce page. Here in this article i will demonstrate how to disable right click on visualforce page using javascript.
Let’s take a simple example:
The below visualforce page is a simple entry page of “Student” custom object. Here the javascript method “RightClickDisabled”, disabled right click in form onmousedown event.
<apex:page standardcontroller="Student__c">
<script>
function RightClickDisabled(event){
if (event.button==2)
{
alert("Right click is not allowed");
}
}
</script>
<apex:form onmousedown="RightClickDisabled(event)">
<apex:pageblock title="Create Student">
<apex:pageblockbuttons>
<apex:commandbutton action="{!save}" value="Save">
</apex:commandbutton></apex:pageblockbuttons>
<apex:pageblocksection columns="1">
<apex:inputfield value="{!Student__c.First_Name__c}">
<apex:inputfield value="{!Student__c.Last_Name__c}">
<apex:inputfield value="{!Student__c.Date_of_Birth__c}">
<apex:inputfield value="{!Student__c.Address__c}">
</apex:inputfield></apex:inputfield></apex:inputfield></apex:inputfield></apex:pageblocksection>
</apex:pageblock>
</apex:form>
</apex:page>
It is so important to restrict double click on visualforce page command button. For example – In an visualforce page, there are some input fields and “Save” button. When user will click on “Save” button, record will insert in to the object. If user will double click that “Save” button at same time, then records will be create twice. In this article I will demonstrate, how to achieve this functionality.
Let’s take a simple example:
To create a password field in visualforce page, you can use inputsecret. InputSecret is an HTML input element of type password.
Let’s take an example:
In below visualforce page there are two input fields Name & Account Number of Account object. Here Account number is in inputsecret. The inputsecret filed of Account Number will act like a password field.