In some cases the user may need to show a multi-lines message, in this post I will explain how to do this.
af:message allows us to include a formatted text in the message, this can be done by surrounding the message text with <html> tags.
So to show a multi-lines message, we can use <p> tag in our message text. The method below displays three lines message.
So to show a multi-lines message, we can use <p> tag in our message text. The method below displays three lines message.
public String shwoMultiLinesMessage() {
StringBuilder builder = new StringBuilder(“<html> <body>”);
builder.append(“<p>First Line</p>”);
builder.append(“<p>Second Line</p>”);
builder.append(“<p>Third Line</p> “);
builder.append(“</body> </html>”);
FacesMessage fm = new FacesMessage(builder.toString());
fm.setSeverity(FacesMessage.SEVERITY_INFO);
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, fm);
return null;
}
StringBuilder builder = new StringBuilder(“<html> <body>”);
builder.append(“<p>First Line</p>”);
builder.append(“<p>Second Line</p>”);
builder.append(“<p>Third Line</p> “);
builder.append(“</body> </html>”);
FacesMessage fm = new FacesMessage(builder.toString());
fm.setSeverity(FacesMessage.SEVERITY_INFO);
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, fm);
return null;
}
The result is af:message with three lines as shown in the image below:
multi-lines message |
Reference: Credits goes to original author Mohamed Jabr.
Are you sure that credits goes to Timo?
ReplyDeletehttp://mjabr.wordpress.com/2011/08/31/how-to-show-multi-lines-afmessage/
You are right it was a reference mistake, sorry for that.
Delete