Using FontAwesome 5.x with PrimeFaces 6.2+

自作多情 提交于 2020-01-02 11:05:14

问题


I was checking this question: How to use Font Awesome from webjars.org with JSF ant this question: FontAwesome with PrimeFaces with its answer https://stackoverflow.com/a/33070133/5113188

Hi I want to use the new icons of https://fontawesome.com/changelog/latest 5.5 version

In my pom.xml file project...

    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>6.2</version>
    </dependency>
    <dependency>
        <groupId>org.primefaces.extensions</groupId>
        <artifactId>primefaces-extensions</artifactId>
        <version>6.2</version>
    </dependency>
    <dependency>
        <groupId>org.omnifaces</groupId>
        <artifactId>omnifaces</artifactId>
        <version>2.1</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.webjars/font-awesome -->
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>font-awesome</artifactId>
        <version>5.5.0</version>
    </dependency>

in my web.xml file

<!-- Fontawesome --> 
<context-param>
    <param-name>primefaces.FONT_AWESOME</param-name>
    <param-value>true</param-value>         
</context-param>

In my facelet .xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                template="/templates/template.xhtml">
    <ui:define name="body">
        <h:outputScript library="webjars" name="font-awesome/5.5.0/js/all.js"/>

...

    <p:spacer width="10"/>6
    <h:outputText styleClass="fas fas-map"/>7
    <h:outputText styleClass="fa fa-venus-mars fa-icon-custom" />
    <h:outputText styleClass="fa fa-female fa-icon-custom" />
    <h:outputText styleClass="fa fa-male fa-icon-custom" />

Note: I'm using fas and fa, but neither is working

Like shown my image all icons are failing

How solve this?


回答1:


The ability to use FontAwesome 5 was added in PF 6.2.12 and PF 6.3. See this ticket and commit which adds the ability:

https://github.com/primefaces/primefaces/issues/4276

https://github.com/primefaces/primefaces/commit/c28c0bccc615bffb99c30825c8c7d8084c3a72da

Turn default PF support OFF in web.xml:

<context-param>
     <param-name>primefaces.FONT_AWESOME</param-name>
     <param-value>false</param-value>         
</context-param>

Update your pom.xml.

<dependency>
     <groupId>org.webjars</groupId>
     <artifactId>font-awesome</artifactId>
     <version>5.8.2</version>
</dependency>

Use the proper WebJars CSS for JSF.

<h:outputStylesheet library="webjars" name="font-awesome/5.8.2/css/all.min-jsf.css" />
<h:outputStylesheet library="webjars" name="font-awesome/5.8.2/css/v4-shims.min-jsf.css" />

NOTE: You will have to change your "fa" as now Font Awesome has separated into different categories like"fas" "fab" etc. Please see the documentation here.



来源:https://stackoverflow.com/questions/53782404/using-fontawesome-5-x-with-primefaces-6-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!