I wanted to override the appearance of .ui-menubar
- however, anything I put in my default.css is not taking because it is overriden by the Primefaces components.css that somehow comes after it.
I have attempted to change the order by using facets as follows:
<h:head>
<f:facet name="first">
<title>Report Title</title>
<meta http-equiv="X-UA-Compatible" content="IE=11; IE=10; IE=9; IE=8; IE=7; IE=EDGE"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</f:facet>
<f:facet name="last">
<h:outputStylesheet name="css/default.css"/>
</f:facet>
</h:head>
Note that this section is part of a template.
Which renders as follows:
<head id="j_idt2">
<title>Report Title</title>
<meta http-equiv="X-UA-Compatible" content="IE=11; IE=10; IE=9; IE=8; IE=7; IE=EDGE">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="/my-web/javax.faces.resource/theme.css.xhtml?ln=primefaces-redmond">
<link type="text/css" rel="stylesheet" href="/my-web/javax.faces.resource/css/default.css.xhtml">
<link type="text/css" rel="stylesheet" href="/my-web/javax.faces.resource/components.css.xhtml?ln=primefaces&v=6.2">
[javascript resources omitted for brevity ...]
</head>
I was using the latest Primefaces which is at time of writing 6.2.
The rendered output, clearly shows components.css
after my custom default.css
.
How can this be correctly ordered?
Note that I can override the style correctly if I avoid using <h:outputStylesheet>
, example as follows:
<f:facet name="last">
<style>
.ui-menubar {
padding: 0px;
margin: 0px;
}
</style>
</f:facet>
That is my workaround, but I consider that not a proper design by hardcoding this in my page, rather than a css.
Note that there are several other similar postings, but I need to emphasize that I DO use and want to use the proper ordering of <h:outputStylesheet>
output, and not some other workaround using inline styles etc. Also I am not yet able to find a duplicate posting with a working answer, although I am continuing to research.
Also note that PrimeFaces documents the use of <f:facets>
within the <h:head>
tag very clearly:
PrimeFaces has it’s own HeadRenderer implementing the following order:
- “first” facet if defined
- Theme CSS
- “middle” facet if defined
- PF-JSF registered CSS and JS
- Head content
- “last” facet if defined
This means the last facet after anything else.