How to use FacesMessage to show multiline message

Sharing is Caring

The faces message component is used to show confirmation, warning or informational message in Oracle ADF. In this tutorial, you will see that how to use FacesMessage component to show Multiline Message. Sometimes we need to show multiline message then how can we implement this?

this is same as FacesMessage implementation, you should know that af:messages support HTML formatting, so we use HTML formatting to show multiline messages
Learn more about FacesMessage and inline message

Managed bean code to show multiline message in ADF using FacesMessage

    package multilineMessages.view.bean;

    import javax.faces.application.FacesMessage;
    import javax.faces.context.FacesContext;
    import javax.faces.event.ActionEvent;

    public class MultilineMessageBean {
        public MultilineMessageBean() {
        }

        public void showMessage(ActionEvent actionEvent) {
StringBuilder message = new StringBuilder("<html><body>");
message.append("<p><b>Hi This is Frist Line--Oracle ADF Message</b></p>");
message.append("<p><i>Hi This is Second Line--Oracle ADF Message</i></p>");
message.append("<p><b>Hi This is Third Line--Oracle ADF Message</b></p>");
message.append("</body></html>");
FacesMessage fm = new FacesMessage(message.toString());
fm.setSeverity(FacesMessage.SEVERITY_INFO);
FacesContext fctx = FacesContext.getCurrentInstance();
fctx.addMessage(null, fm);
        }
    }

To use for Error and Warning just change FacesMessage.SEVERITY_INFO to SEVERITY_ERROR or SEVERITY_WARN.
It will look like this
You can change your Message accordingly

you can also use some HTML styles (CSS) to change color of text that appears in the message body, see the changed code

    public void showMessage(ActionEvent actionEvent) {
        StringBuilder message = new StringBuilder("<html><body>");
        message.append("<p style='color:navy'><b>Hi This is Frist Line--Oracle ADF Message</b></p>");
        message.append("<p style='color:green'><i>Hi This is Second Line--Oracle ADF Message</i></p>");
        message.append("<p style='color:magenta'><b>Hi This is Third Line--Oracle ADF Message</b></p>");
        message.append("<p style='color:red'><b><i>This is Fourth line--Oracle ADF Message</i></b></p>");
        message.append("</body></html>");
        FacesMessage fm = new FacesMessage(message.toString());
        fm.setSeverity(FacesMessage.SEVERITY_INFO);
        FacesContext fctx = FacesContext.getCurrentInstance();
        fctx.addMessage(null, fm);
    }

now see the FacesMessage look like this-

show multiline message

Happy Learning 🙂 Download Sample App

Related Posts

3 thoughts on “How to use FacesMessage to show multiline message”

  1. Hi Ashish,
    How can we show HTML table in the ADF faces message?

    I tried setting up the String — “Records didn’t proccessed successfully.Please check the errors belowBatchIDLine NumberError Message10791Error 2 ORA-01403: no data found10792Error 2 ORA-01403: no data found” in the Faces Message and it printed only content.

    Thanks,
    Vishal Kumar

Leave a Reply

Your email address will not be published. Required fields are marked *