从Primefaces对话框中删除标题



有没有办法从使用Primefaces对话框框架打开的对话框中删除标题?我知道我可以设置一个自定义标头(请参阅截取的代码),但是如何删除它?我不想从所有对话框中删除它,因此无法覆盖 CSS 类.ui-dialog .ui-dialog-titlebar

 Map<String,Object> options = new HashMap<String, Object>();
        options.put("modal", true);
        options.put("width", 640);
        options.put("height", 340);
        options.put("contentWidth", "100%");
        options.put("contentHeight", "100%");
        options.put("headerElement", "customheader");
        RequestContext.getCurrentInstance().openDialog("viewCars", options, null);
以防

万一有人偶然发现同样的问题。您只需在页面中覆盖:

.ui-dialog-titlebar{
display:none;
}

你可以在jQuery的Class Selector的帮助下做到这一点。

在要显示对话框的页面中添加以下java脚本

        <script type="text/javascript">
            function removeDialogHeader(xhr, status, args){
                var showHeader=args.showDialogHeader;
                if (!showHeader){
                    //jquery gets all elements with class name ui-dialog-titlebar
                    var elements= $(".ui-dialog-titlebar");
                    //to remove elements
                    elements.remove();
                    //or you can achive the same effect by inserting display:none into element style
                    //elements.css("display", "none");
                }
            }
        </script>

修改受管 Bean 方法以使标头可见性可配置

public void viewCars() {
    Map<String,Object> options = new HashMap<String, Object>();
    options.put("resizable", false);
    //...
    RequestContext.getCurrentInstance().openDialog("viewCars", options, null);
    RequestContext.getCurrentInstance().addCallbackParam("showDialogHeader", false);
}

并且,假设你有 p:commandButton 来显示对话框,在 Ajax 完成后调用 JS 函数

<p:commandButton value="Show dialog" actionListener="#{testBean.viewCars()}" oncomplete="removeDialogHeader(xhr, status, args);"/>

只需使用 p:dialogshowHeader 属性,如以下示例所示:

<p:dialog widgetVar="exampleWidget" showHeader="false">
  <!-- your content -->
</p:dialog>

"删除标题"是什么意思?可能是"不显示标题"?如果是这样,您可以定义一个 css 类,如下所示:

.dialog-no-header.ui-dialog .ui-dialog-titlebar {
    display: none;
}

并在目标对话框中使用它:

<p:dialog class="dialog-no-header" ...

最新更新