有没有办法从使用Primefaces Dialog Framework打开的对话框中删除标题?
我知道我可以设置自定义标题(请参阅代码剪切),但是如何删除它?我不想从所有对话框中删除它,因此不能覆盖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);
答案 0 :(得分:1)
你可以借助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);"/>
答案 1 :(得分:0)
以防万一有人偶然发现同一问题。您可以在页面中直接覆盖:
.ui-dialog-titlebar{
display:none;
}
答案 2 :(得分:0)
“删除标题”是什么意思?可能是“不显示标题”?如果是这样,您可以定义一个CSS类,如:
.dialog-no-header.ui-dialog .ui-dialog-titlebar {
display: none;
}
并在目标对话框中使用它:
<p:dialog class="dialog-no-header" ...