Issue
Is there a way to remove the header from a dialog opened with the Primefaces Dialog Framework?
I know I can set a custom header (see code snipped), but how to remove it at all? I don't want to remove it from all dialog, so overriding the CSS class .ui-dialog .ui-dialog-titlebar is not an option.
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);
Solution
You can do it with help of jQuery's Class Selector.
Add following java script inside page where you want to show dialog
<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>
modify managed bean method to make header visibility configurable
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);
}
and, assuming that you have p:commandButton to show dialog, call JS function after Ajax is completed
<p:commandButton value="Show dialog" actionListener="#{testBean.viewCars()}" oncomplete="removeDialogHeader(xhr, status, args);"/>
Answered By - Dusan Kovacevic
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.