PrimeFaces provides improved resource ordering to support customization of content. This ability could be used when Internet Explorer demands special meta tags to be placed first or for scenarios where the styling for PrimeFaces components needs to be overridden by custom styling.
Define <h:head>
using facet definitions where necessary:
<h:head title="PrimeFaces Cookbook - ShowCase"> <f:facet name="first"> </f:facet> ... <f:facet name="middle"> </f:facet> ... <f:facet name="last"> </f:facet> ... </h:head>
For instance, if a stylesheet gets declared in multiple CSS files, which would be linked in the middle and last facets respectively, the stylesheet definition referred to in the middle
facet will be overridden by the one defined in the last
facet.
With PrimeFaces' own HeadRenderer
implementation, the resources are handled in the following order:
Internet Explorer introduced a special tag named meta
, which can be used as <meta http-equiv="X-UA-Compatible" content="..." />
. The <meta>
tag is X-UA-Compatible and its content helps to control document compatibility, such as specifying the rendering engine to render the related pages in the browser. For example, inserting the following statement into the head of a document would force IE 8 to render the page using the new standards mode:
<meta http-equiv="X-UA-Compatible" content="IE=8" />
X-UA-Compatible must be the first child of the head
component. Internet Explorer won't accept this <meta>
tag if it's placed after the <link>
or <script>
tag. Therefore, it needs to be placed within the first
facet. This is a good demonstration of resource ordering with the use of the first
facet.
This recipe is available in the demo web application on GitHub (https://github.com/ova2/primefaces-cookbook/tree/second-edition). Clone the project if you have not done it yet, explore the project structure, and build and deploy the WAR file on application servers compatible with Servlet 3.x, such as JBoss WildFly and Apache TomEE.
The showcase for the recipe is available at http://localhost:8080/pf-cookbook/views/chapter1/resourceOrdering.jsf
.
3.147.84.157