Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include the contents of a stylesheet in <style>?

Tags:

html

css

jsf

jsf-2

I have a JSF 2.0 page that uses this:

<h:head>
<h:outputStylesheet name="screen.css" library="css" />
</h:head>

Which very nicely generates this HTML:

<head>
<link type="text/css" rel="stylesheet" 
    href="/myapp/javax.faces.resource/screen.css.jsf?ln=css" />
</head>

This is great when the page is being viewed in a browser. However, I want to use this stylesheet embedded in an HTML page that will be emailed to the user. I don't want their email client to load the stylesheet from the server. I want the document emailed to them to be self-sufficient and not be influenced by changes in (or even the absence of) the stylesheet on the website.

I want the HTML output to be like this:

<head>
<style type="text/css">
    ...contents of screen.css here...
</style>
</head>

I tried to achieve that by using this:

<h:head>
<style type="text/css">
<ui:include src="/resources/css/screen.css"></ui:include>
</style>
</h:head>

But I received this error:

javax.servlet.ServletException: Error Parsing /resources/css/screen.css: 
Error Traced[line: 1] Content is not allowed in prolog.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:325)

How can I get the contents of the stylesheet to appear in the head of the document?

like image 684
Mr. Lance E Sloan Avatar asked Dec 21 '25 17:12

Mr. Lance E Sloan


1 Answers

Not with standard JSF components.

The JSF utility library OmniFaces has an <o:resourceInclude> for the very purpose of including the raw output of non-JSF webapp resources in a JSF page.

<h:head>
    <style type="text/css">
        <o:resourceInclude path="/resources/css/screen.css" />
    </style>
</h:head>

Note that this doesn't support resource localization and versioning, nor evaluate EL expressions in CSS files like as <h:outputStylesheet> would do.

like image 120
BalusC Avatar answered Dec 24 '25 10:12

BalusC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!