Newline in

前端 未结 6 854
不知归路
不知归路 2021-01-12 11:49

Is there a way to put a new line in the message of component?



        
相关标签:
6条回答
  • 2021-01-12 11:49

    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.

    0 讨论(0)
  • 2021-01-12 11:50

    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>
    
    0 讨论(0)
  • 2021-01-12 11:53

    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>
    
    0 讨论(0)
  • 2021-01-12 11:59

    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>
    
    0 讨论(0)
  • 2021-01-12 12:07

    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>  
    
    0 讨论(0)
  • 2021-01-12 12:16

    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.

    0 讨论(0)
提交回复
热议问题