Today's problem to solve is, how to add a custom alert message in ADF ?
ADF components has built in alert message when it comes to component level validation. But when you need to display a custom alert message before or after processing an action, then you need to something like shown below.
In general there are two kinds of messages that can be created. One at the component level message and the other is global level messages. Component level messages are associated with the clientId that was passed to the addMessage method. Global level messages are not asscociated to any components and so clientID is set to null when calling the addMessage method.
The following method needs to be added to the back-end bean.
Here is an example...
// import statements
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
/**
* Method to display custom alert message.
*/
public String showMessage(){
String msg= "Global alert message to display";
FacesContext ctx = getContext();
FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, "");
ctx.addMessage(null,fm);
return null;
}
/**
* @param
* Method to return the current context .
*/
private FacesContext getContext() {
return FacesContext.getCurrentInstance();
}
Other Message Severity Levels are ....
FacesMessage.Severity SEVERITY_ERROR Message severity level indicating an error.
FacesMessage.Severity SEVERITY_FATAL Message severity level indicating about a serious error.
FacesMessage.Severity SEVERITY_INFO Message severity level indicating an informational message.
FacesMessage.Severity SEVERITY_WARN Message severity level indicating a warning message.
Output:
No comments:
Post a Comment