9

Is there a way to put a new line in the message of <p:confirm> component?

<p:confirm header="Confirmation"  
    message="Are you sure you want to continue? Bla bla bla" 
    icon="ui-icon-alert"  />

I would like to have "Bla bla bla" in a new line.

qxlab
  • 1,506
  • 4
  • 20
  • 48

6 Answers6

5

Message is HTML part, so you need to add <br>. Either take message from bean (to prevent xml tag escaping) or use facet:

<p:confirmDialog header="Confirmation">
    <f:facet name="message">
        Are you sure you want to continue?<br/>Yes or no?
    </f:facet>
</p:confirmDialog>  
Web Devie
  • 1,207
  • 1
  • 13
  • 30
  • 1
    Thank you for the answer. I'm using a global `confirmDialog`, is there any way I could do this line break inside the `p:confirm` component? Thanks – qxlab Dec 04 '13 at 13:06
  • Have you tried? This snippet throws `FaceletException` because it's invalid XML. – BalusC Dec 05 '13 at 10:24
  • 1
    Thanks @BalusC, I was using
    but I've wanted to use valid HTML here. Funny, that the most correct syntax is not accepted :(
    – Web Devie Dec 06 '13 at 07:57
  • Uh, HTML4 is indeed not valid XML, no, that's also exactly why XHTML and HTML5 exist. How could you miss that fact as "web devie" and particularly JSF developer? See also among others http://stackoverflow.com/questions/2935759/is-it-possible-to-use-jsffacelets-with-html-4-5/3869174#3869174 and http://stackoverflow.com/tags/xhtml/info – BalusC Dec 06 '13 at 09:39
  • what we do if we need multiple confirm box at the same page? – Ramesh Rajendran Jun 01 '17 at 20:27
3

At the time I asked this question there was no escape option in confirm component but it was implemented on PrimeFaces 6.2 after this feature request.

So now we can just do it this way:

<p:confirm header="Confirmation"  
    escape="false"
    message="Are you sure you want to continue? &lt;br/&gt; Bla bla bla" 
    icon="ui-icon-alert"  />

Alternatively, it's possible to use confirmDialog component as already suggested in other answers.

qxlab
  • 1,506
  • 4
  • 20
  • 48
2

There's no "escape" attribute in p:confirm, so you may try this. (Which is work when I tried it.)

Page:

<p:commandButton value="Show the Dialog" 
                 onclick="#{MyBean.setMsg('Are you sure you want to continue? &lt;br/&gt; Bla bla bla')}" 
                 oncomplete="conf.show()" update="confDlg">
</p:commandButton>
<p:confirmDialog id="confDlg" severity="alert" header="Confirmation" widgetVar="conf" global="true">   
    <f:facet name="message">
       <h:outputText value="#{MyBean.msg}" escape="false"/>
    </f:facet>
</p:confirmDialog> 

Backing Bean:(simply getter and setter)

   private String msg;

public void setMsg(String msg) {
    this.msg = msg;
}

public String getMsg() {       
    return msg;
}

In this way, you can also take advantage of global confirmDialog.

However, you may need to edit other commandButtons that show confirmDialog.

nosnhoj
  • 793
  • 1
  • 12
  • 30
2

very easy you can use facet

<p:confirmDialog widgetVar="cd" header="Confirm">
     <f:facet name="message">
        <h:outputText value="Are you sure?" />
        <br />
        <h:outputText value="After line break" />
     </f:facet>
    ...
 </p:confirmDialog>
Bilal2005
  • 66
  • 4
  • 3
    Why are you repeating an already given answer? This is a Q&A site, not an old fashioned discussion forum. – BalusC Jan 22 '14 at 08:42
2

This works for me:

<p:confirm header="Confirm title" icon="ui-icon-help" message="This Line\n Next Line" />

and style:

<p:confirmDialog global="true" style="white-space: pre;">
...
</p:confirmDialog>
tchudyk
  • 564
  • 4
  • 14
0

I have many different messages to show, then I put it into List and do something like that in page:

<p:confirmDialog>
  <f:facet name="message">
    <ui:repeat value="#{bean.list}" var="item">
      <p:panel>
        <h:outputText value="#{item}"/>
      </p:panel>
    </ui:repeat>
  </f:facet>
</p:confirmDialog>