3

<p:dataTable>右键单击其中的一行时,会<p:contextMenu>出现一个删除选项。单击此选项时,将<p:confirmDialog>出现两个按钮YesNo- 关于删除当前行的构象警告,如下所示。

<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在此对话框上使用格式化消息设置属性。

例如,testManagedBean.message其托管 bean 中的属性设置为类似

You are about to delete <font color='#ff0000'>2</font> rows. <br/>This action will never be undone. <br/>Are you sure?

确认对话框将这个字符串显示为一个整体。此字符串中的 HTML 应被解释为 HTML。我没有看到像escapein那样的任何属性<p:confirmDialog>

有没有办法将此字符串显示为格式化消息。

4

1 回答 1

12

我发现了一个丑陋<f:facet name="message">的嵌套 inside 解决方案<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>

从中删除message属性<p:comfirmDialog>并将其嵌套<f:facet name="message">在其中。

注意:<h:outputFormat>仅当需要通过嵌套传递一个或多个参数以<f:param>替换{0}消息文本中的相应占位符()时才需要。<h:outputText escape="false">如果不需要传递此类参数,请继续使用。

于 2013-11-10T01:26:06.370 回答