2

I have sample Spring Boot project for PrimeFaces and looking for a way to make awesomefont to work as shown in PF Showcase.

So I created awesomefont-test.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">

<h:head>
  <title>Awesomefont Test</title>
</h:head>

<h:body>

    <p:commandButton value="Edit" icon="fa fa-fw fa-edit" type="button"/>

</h:body>
</html>

and the result is (no icon)

button without awesomefont icon

I tried several things:

1.) web.xml

I created web.xml and I tried to put it next to faces-config.xml (which is in jsf-primefaces-spring-boot/src/main/resources/META-INF/).

I tried to put it to jsf-primefaces-spring-boot/src/main/resources/WEB-INF/ not working too.

I do not know how to check it is read.

content:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

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

</web-app>

2.) SpringBootServletInitializer

package com.codenotfound.primefaces;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer;

@SpringBootApplication
public class SpringPrimeFacesApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(SpringPrimeFacesApplication.class, args);
    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        servletContext.setInitParameter("primefaces.FONT_AWESOME", "true");
        super.onStartup(servletContext);
    }

}

source: How to set context-param in spring-boot

3.) application.properties

From same source I tried to set property in application.properties

server.context_parameters.primefaces.FONT_AWESOME=true

also I tried variant with

server.servlet.context-parameters.primefaces.FONT_AWESOME=true

4.) webjars

This is a workaround, I just wanted to give it a try.

I also tried to add webjars dependencies (and modify xhtml) as described here - http://www.littlebigextra.com/add-bootstrap-css-jquery-to-springboot-mvc/

but none of those approaches worked for me.

Betlista
  • 10,327
  • 13
  • 69
  • 110
  • Better article for webjarshttps://stackoverflow.com/questions/18891768/how-to-use-font-awesome-from-webjars-org-with-jsf/28652968#28652968. The article you refer to is not correct for JSF... And using WebJars is in mo opinion the better way. PF should not have included it themselves – Kukeltje Apr 12 '18 at 08:26
  • And FA from PrimeFaces is not supported in PF 1.0 – Kukeltje Apr 12 '18 at 08:27
  • @Kukeltje I tried your advice, but it is not working for me - I added dependency in maven + `` which is rendered in page source as `` I'm using PF 6.1 – Betlista Apr 12 '18 at 11:16
  • Finally, I noticed, there is version in link and I had different as dependency. Also I tried `fas` class, but with 4.x I had to use `fa`. – Betlista Apr 12 '18 at 11:21
  • So it works now? – Kukeltje Apr 12 '18 at 17:20
  • 1
    Yes, it works with version 4.7.0, with 5.0.9 I had `href="RES_NOT_FOUND"` again on page. – Betlista Apr 12 '18 at 19:49
  • I made it work using the font awesome javascript library instead. Ex. – tainos Apr 14 '18 at 18:09

2 Answers2

0

After defining the dependency in pom.xml:

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

You need to add config into application.yml:

jsf:
  primefaces: 
    FONT_AWESOME: true

or if use application.properties add:

jsf.primefaces.FONT_AWESOME=true
swist
  • 1,111
  • 8
  • 18
0

You don't need to create a web xml, just add the dependency and in your application.properties add this:

jsf.primefaces.font-awesome=true

And if you what to configure a theme add this:

jsf.primefaces.theme= theme-name
xskxzr
  • 12,442
  • 12
  • 37
  • 77