在p:confirmDialog上显示格式化的文本/消息 [英] Display a formatted text / message on p:confirmDialog
问题描述
当 <p:dataTable>
中的一行正确时,单击后,出现 <p:contextMenu>
并带有删除选项.单击此选项后, <p:confirmDialog>
出现并带有两个按钮No
-有关删除当前行的警告,如下所示.
When a row in <p:dataTable>
is right-clicked, <p:contextMenu>
appears with a delete option. When this option is clicked, <p:confirmDialog>
appears with two buttons Yes
and No
- a conformation warning about deleting the current row as follows.
<p:contextMenu for="dataTable">
<p:menuitem oncomplete="confirmDelete.show()"
value="Delete"
update="confirmDialog"
process="@this dataTable"
actionListener="#{testManagedBean.deleteActionListener}"
icon="ui-icon-close" ajax="true"/>
</p:contextMenu>
<p:confirmDialog id="confirmDialog"
widgetVar="confirmDelete"
message="#{testManagedBean.message}"
header="Message"
severity="alert"
closeOnEscape="true"
showEffect="slide"
hideEffect="fold"
appendTo="@(body)"
closable="true">
<p:commandButton id="btnYes"
value="Yes"
process="@this"
oncomplete="confirmDelete.hide()"
actionListener="#{testManagedBean.deleteActionListener}"
update="dataTable"/>
<p:commandButton id="btnNo"
value="No"
onclick="confirmDelete.hide()"
type="button" />
</p:confirmDialog>
在此对话框上是否可以用格式化的消息设置message
属性.
Is there a way to set the message
attribute with a formatted message on this dialog.
例如,其托管bean中的属性testManagedBean.message
设置为类似字符串
For example, the property testManagedBean.message
in its managed bean is set to a string like
You are about to delete <font color='#ff0000'>2</font> rows. <br/>This action will never be undone. <br/>Are you sure?
确认对话框将整体显示此字符串.此字符串中的HTML应该解释为HTML.我没有在<p:confirmDialog>
中看到任何类似escape
的属性.
The confirm dialog displays this string as a whole. HTML in this string should be interpreted as HTML. I don't see any attribute like escape
in <p:confirmDialog>
.
有没有办法将此字符串显示为格式化的消息.
Is there a way to display this string as a formatted message.
推荐答案
我在<p:confirmDialog>
中发现了<f:facet name="message">
.
I found an ugly solution nesting of <f:facet name="message">
within <p:confirmDialog>
.
<p:confirmDialog id="confirmDialog"
widgetVar="confirmDelete"
header="Message"
severity="alert"
closeOnEscape="true"
showEffect="slide"
hideEffect="fold"
appendTo="@(body)"
closable="true">
<p:commandButton id="btnYes"
value="Yes"
process="@this"
oncomplete="confirmDelete.hide()"
actionListener="#{testManagedBean.deleteActionListener}"
update="dataTable"/>
<p:commandButton id="btnNo"
value="No"
onclick="confirmDelete.hide()"
type="button" />
<f:facet name="message">
<h:outputFormat value="#{testManagedBean.message}" escape="false"/>
</f:facet>
</p:confirmDialog>
从<p:comfirmDialog>
中删除message
属性,并将<f:facet name="message">
嵌套在其中.
Removing the message
attribute from <p:comfirmDialog>
and nesting <f:facet name="message">
inside it.
注意:仅当需要通过嵌套<f:param>
传递一个或多个参数以替换消息文本中相应占位符({0}
)时,才需要<h:outputFormat>
.如果不需要传递此类参数,请继续使用<h:outputText escape="false">
.
Note : <h:outputFormat>
is only needed, if one or more parameters need to be passed by means of nested <f:param>
to be substituted in respective placeholders ({0}
) in the message text. Just keep on using <h:outputText escape="false">
, if no such parameters need to be passed.
这篇关于在p:confirmDialog上显示格式化的文本/消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!