2
votes

For a university project I am using a skeleton project running PrimeFaces 6.2 on a Maven Web Application with Spring Boot. By default, this project applies the aristo style.

I have tried to change this by following the instructions at https://www.primefaces.org/themes/.

  1. Added PrimeFaces Repository to pom.xml

    <repository>
        <id>prime-repo</id>
        <name>PrimeFaces Maven Repository</name>
        <url>http://repository.primefaces.org</url>
        <layout>default</layout>
    </repository>
    
  2. Added dependency to the all-themes file in pom.xml

    <dependency>
        <groupId>org.primefaces.themes</groupId>
        <artifactId>all-themes</artifactId>
        <version>1.0.10</version>
    </dependency>
    
  3. Added context-param to src/main/webapp/WEB-INF/web.xml

    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>cruze</param-value>
    </context-param>

However, the value at the web.xml gets ignored completely. Other values from this web.xml are used, however no matter what I put into the primefaces.THEME param, it will not be used. Even completely random values are accepted by the program and it will run just fine. Same with putting 'none', the same style is used still.

I have tried some solutions to similiar questions that haven't worked.

  • Using a jar file instead of the pom.xml dependency - This does not affect anything since the value just gets ignored in the first place.
  • My faces-config is not using a render kit, so this is not helping either.
  • Using h:head - This is already the case.
  • Using the xmlns:p="http://primefaces.org/ui" attribute in the html tag - Also already the case.
  • The web.xml is of version 2.5, so the context-param syntax should be valid.

Is there any chance PrimeFaces is expecting the theme at a different place other than web.xml?

Addition: My problem is the same as described here. I am pretty certain it is using the same skeleton project, except on a newer PrimeFaces version.

Full web.xml file (tested with different primefaces.THEME values)

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

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <error-page>
        <exception-type>org.springframework.security.access.AccessDeniedException</exception-type>
        <location>/error/access_denied.xhtml</location>
    </error-page>


    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>none</param-value>
    </context-param>

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>login.xhtml</welcome-file>
    </welcome-file-list>
</web-app>
1
Something else must be wrong then. Is your JSF servlet setup correctly? PF only uses the web.xml and does not accept random values. See github.com/primefaces/primefaces/blob/6_2/src/main/java/org/…Jasper de Vries
As far as I can tell the servlet is set up correctly as all the xhtml files are rendered properly and the default Prime Faces Style (Aristo) is applied to all "p:" elements without any extra styling. But the value in the web.xml is just completely ignoredxerox102
As edited in the main question, this question was already asked once about the same skeleton project at stackoverflow.com/questions/43416136/…, but didn't receive a specific answer there either.xerox102
HAve you tried using JoinFaces rather than rolling your own PF+Spring Boot. JoinFaces already fixes all these issues.Melloware
What does the EL #{facesContext.externalContext.getInitParameter('primefaces.THEME')} output?Selaron

1 Answers

3
votes

It seems that Spring in general influences/ignores/... context-parameters from the web.xml. The solution below feels more of a workaround, since the empty output of #{facesContext.externalContext.getInitParameter('primefaces.THEME')} very clearly suggested the parameter was not being passed from the web.xml, I have instead created a ServletContextInitializer which passes the parameter on startup.

@Configuration
public class CustomServletContextInitializer implements ServletContextInitializer {

    @Override
    public void onStartup(ServletContext sc) throws ServletException {
        sc.setInitParameter("primefaces.THEME", "cruze");
    }

}