Sunday, August 30, 2009

Showing a Confirmation Message


Faces Message can have there severity specified. Inbuilt severity are for fatal,error,warning and information.

To get a confirmation message we can use FacesMessageUtils.getConfirmationMessage which takes a FacesMessage as input.

This is the managed bean code

public void onClick(ActionEvent actionEvent) {
// Add event code here...
String sb = "My Confirmation Message";
FacesContext ctx = FacesContext.getCurrentInstance();
FacesMessage msg =
FacesMessageUtils.getConfirmationMessage(new FacesMessage(sb.toString()));
ctx.addMessage(null, msg);
}

I have bounded the Action listener of command button to above code


Now lets see if you want to format the message, how to do it.


public void onClick(ActionEvent actionEvent) {
// Add event code here...
StringBuilder sb = new StringBuilder();
sb.append("<html>");
sb.append("ADF");
sb.append(" <br> is cool! </br>");
sb.append("<hr> So is <b> Jdevloper</b>");
sb.append("</html>");
FacesContext ctx = FacesContext.getCurrentInstance();
FacesMessage msg =
FacesMessageUtils.getConfirmationMessage(new FacesMessage(sb.toString()));
ctx.addMessage(null, msg);


}

No comments:

Post a Comment