Issue
I can't import custom fonts into my JSF pages. Project structure looks like this:
I've tried to write the following in my styles.css:
@font-face {
font-family: "Gotham Pro Bold";
src: url('#{resource["fonts/GothaProBol.otf"]}');
}
But it doesn't work. It gets compiled to /javax.faces.resource/fonts/GothaProBol.otf.xhtml
, but the font is not in javax.faces.resource
and I have no idea why it appends .xhtml
.
The following:
src: url("#{facesContext.externalContext.requestContextPath}/resources/fonts/GothaProBol.otf");
is compiled to
src: url("/resources/fonts/GothaProBol.otf");
but it doesn't work either.
How do I import the fonts properly?
Thanks in advance.
Solution
Did this using OmniFaces:
- Added the dependency (
pom.xml
):
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>1.8.1</version>
</dependency>
- Added OmniFaces' resource handler to
faces-config.xml
:
<application>
<resource-handler>
org.omnifaces.resourcehandler.UnmappedResourceHandler
</resource-handler>
</application>
- Mapped
/javax.faces.resource/*
toFacesServlet
as follows (web.xml
):
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/javax.faces.resource/*</url-pattern>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
- Used
#{resource["<path>"]}
in CSS, like so:
@font-face {
font-family: "Gotham Pro Bold";
src: url('#{resource["fonts/GothaProBol.otf"]}');
}
Answered By - Dmitriy Tkachenko
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.