HTML标记和换行不适用于p:confirmDialog

时间:2014-07-23 15:34:00

标签: html jsf-2 primefaces

我想使用html标记或带有<p:confirmDialog>消息的新行。

Xhtml

<h:form>
  <p:commandButton value="Open Confirm Dialog" actionListener="#{bean.getConfirmDlgMsg}" update="confirmDlgId" oncomplete="confrimDlg.show();"/>
</h:form>

<p:confirmDialog id="confirmDlgId" widgetVar="confrimDlg" header="Test Header"
message="#{bean.msg}">
   <p:commandButton value="Yes"/>
   <p:commandButton value="No"/>
</p:confirmDialog>

Bean

private String msg;
//getter and setter for msg
public void getConfirmDlgMsg()
{
  StringBuilder sb=new StringBuilder();
  sb.append("Hi");
  sb.append("\n");
  sb.append("<b>Welcome</b>");
  setMsg(sb.toString());
}

confirmDialog消息必须类似于

您好 的欢迎

但我明白了 嗨<b>欢迎</b>

由于\n无效,我尝试<br/>。但这些标签正在印刷。

然后我尝试sb.append(String.format("<strong> %s <strong>")","Welcome");<strong>正在打印。

然后使用<font><font>

我尝试使用StringBuffer代替StringBuilder。但是没有变化。

然后我将confirmDialog更改为

<p:confirmDialog id="confirmDlgId" widgetVar="confrimDlg" header="Test Header">
   <f:facet name="message">
     <h:outputFormat value="#{bean.msg}" escape="false"/>
   </f:facet>
   <p:commandButton value="Yes"/>
   <p:commandButton value="No"/>
</p:confirmDialog>

此处不会打印标签,但消息的必需部分不会变为粗体。

之前我已成功使用/ n和<br/>StringBuilder

我想知道HTML标记或换行符是否不适用于<p:confirmDialog>。 还有,有没有办法使用<p:confirDialog>

我使用primefaces 4和jsf 2.2。

先谢谢你。

1 个答案:

答案 0 :(得分:0)

使用css

获得解决方案

Xhtml

#confirmDlgId span.makeBold
{
    font-weight:bold;
}

<p:confirmDialog id="confirmDlgId" widgetVar="confrimDlg" header="Test Header">
   <f:facet name="message">
     <h:outputFormat value="#{bean.msg}" escape="false"/>
   </f:facet>
   <p:commandButton value="Yes"/>
   <p:commandButton value="No"/>
</p:confirmDialog>

Bean

private String msg;
//getter and setter for msg
public void getConfirmDlgMsg()
{
  StringBuilder sb=new StringBuilder();
  sb.append("Hi");
  sb.append("\n");
  sb.append("<span class="makeBold">Welcome</span>");
  setMsg(sb.toString());
}