2

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>
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
xerox102
  • 101
  • 11
  • 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 https://github.com/primefaces/primefaces/blob/6_2/src/main/java/org/primefaces/renderkit/HeadRenderer.java – Jasper de Vries Dec 02 '19 at 16:06
  • 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 ignored – xerox102 Dec 02 '19 at 17:14
  • As edited in the main question, this question was already asked once about the same skeleton project at https://stackoverflow.com/questions/43416136/primefaces-theme-does-not-apply-maven, but didn't receive a specific answer there either. – xerox102 Dec 02 '19 at 17:27
  • HAve you tried using JoinFaces rather than rolling your own PF+Spring Boot. JoinFaces already fixes all these issues. – Melloware Dec 02 '19 at 19:42
  • What does the EL `#{facesContext.externalContext.getInitParameter('primefaces.THEME')}` output? – Selaron Dec 02 '19 at 19:54
  • And what does `RequestContext.getCurrentInstance(FacesContext.getCurrentInstance()).getApplicationContext() .getConfig().getTheme();` return when invoked in a bean? – Selaron Dec 02 '19 at 20:21
  • Both of these output empty strings. In this project I don't think we are supposed to change the technology stack so I'm not sure if using JoinFaces is a good solution. I am editing the question to include the full web.xml, but it is pretty much the same as in the linked question. I've tried a lot of different values for primefaces.THEME and none of them have any effect. – xerox102 Dec 02 '19 at 21:08
  • 2.5 for web.xml is old... https://stackoverflow.com/questions/15985378/what-exactly-is-the-web-app-version-what-does-it-affect but effectively your question is not jsf or primefaces related but _"why is web.xml or the context parameterd not picked up in my spring based project"_ – Kukeltje Dec 03 '19 at 06:54
  • https://stackoverflow.com/questions/55064653/context-param-values-in-web-xml-get-ignored – Kukeltje Dec 03 '19 at 07:52

1 Answers1

3

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");
    }

}
Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
xerox102
  • 101
  • 11
  • See the link in the comments. Could be that spring (did you run it in debug/trace mode?) tries to load AND validate it which most likely fails. Copy/paste it in https://www.xmlvalidation.com/index.php?id=1&L=0 and you'll see it fails. The xsd cannot be found anymore (schemalocation does not exist anymore). And since 2.5 is ooooold, try 3.0 or newer even) – Kukeltje Dec 03 '19 at 07:55
  • Even with 3.0 and the document passing the xmlvalidation page without errors, the style does not load. Neither with 2.5 and a functioning xsd (from the oracle page) The web.xml is otherwise also used, for example for defining the servlet on startup, so it is not completely ignored. Though other context-param values in the skeleton project seem to be ignored as well. – xerox102 Dec 03 '19 at 09:29
  • Faces servlet is in modern jsf and servlet versions loaded automatically with defaults (which you seem to have). If the welcome page works or the access denied page, then it is used. If so find out what spring does with context parameters...https://stackoverflow.com/questions/32945854/specifying-context-param-in-web-xml-while-integrating-spring-and-jersey/32953123 – Kukeltje Dec 03 '19 at 11:37