Monthly Archives: August 2011

How to show multi-lines af:message

Environment (JDeveloper 11.1.2.0.0, ADF Faces)

In the last post, I have explained how to show af:message programatically. 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.

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;
    }

The result is af:message with three lines as shown in the image below:

mult-lines message

multi-lines message

2 Comments

Filed under ADF