(Solved) Primefaces tags not rendering

UI Components for JSF
Post Reply
phanss
Posts: 2
Joined: 16 May 2022, 17:43

16 May 2022, 18:30

Hello,

I tried to set up a JakartaEE 9.1 project in IntelliJ 2022.1 (Ultimate) using JSF 3.0.0 and primefaces 11.0.0. The application is running locally using Glassfish 6.2.5.
I have created a basic .xhtml page from the Hello World page but the primefaces tags are not rendering whereas the JSF tags do render normally as shown in the picture below:

Picture showing the received html source code on the Firefox browser.
Image


index.xhtml is defined as:

Code: Select all

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:jsf="http://xmlns.jcp.org/jsf"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

<f:view contentType="text/html;charset=UTF-8" encoding="UTF-8">
   <h:head>

   </h:head>
   <h:body>
      <p:textEditor />
   </h:body>
</f:view>

</html>
My Web.xml file is as follows:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>
And the pom.xml:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>DADemo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>DADemo</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
        <junit.version>5.8.2</junit.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>jakarta.platform</groupId>
            <artifactId>jakarta.jakartaee-api</artifactId>
            <version>9.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.faces</groupId>
            <artifactId>jakarta.faces-api</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>11.0.0</version>
            <classifier>jakarta</classifier>
        </dependency>

    </dependencies>

    <build>
        <finalName>helloworld</finalName>
        <plugins>
        </plugins>
    </build>
</project>

Could someone please tell me what I'm doing wrong? I'm new into JakartaEE, JSF and web application development and I'm a little bit overwhelmed by all the different settings, options etc. ...

Thank you for reading!
Last edited by phanss on 17 May 2022, 10:25, edited 1 time in total.
Currently working with: PrimeFaces 11.0.0 - JSF 3.0 - Glassfish 6.2.5.
IntelliJ 2022.1 Ultimate Edition

Software engineering student.

phanss
Posts: 2
Joined: 16 May 2022, 17:43

17 May 2022, 10:24

After a few more hours I found the solution, posting it here for anyone who might need it.

Solution
Adding the dependency to your pom.xml file and the namespace in the .xhtml file isn't sufficient to get a browser to show the results (in contrast to what the Getting started page states).

For my configuration two other steps were necessary:

1. Add a html sanitizer dependency to pom.xml so that third party html code can be rendered. Make sure to refresh Maven and download the project resources.

Code: Select all

<dependency>
            <groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
            <artifactId>owasp-java-html-sanitizer</artifactId>
            <version>1.1</version>
        </dependency>
2. Add the Primefaces artifact to the runtime deployment library folder. In IntelliJ that is:
  1. In IntelliJ 2022.1: Right click your project in the project structure tree.
  2. click 'open Module settings'. A window opens.
  3. Navigate to 'Artifacts'.
  4. In the righthand column under 'Available Elements', doubleclick the PrimeFaces 11.0.0 project library and doubleclick all other Project libraries which start with 'com.google'. I also added the 'commons-codec' project library.
The WEB-INF/lib folder in your output root should look something like:
Image

That's all!

P.S.: Note that I am very new to JakartaEE. I do not (yet?) have an idea what a HTML sanitizer is for. I also might use certain terminology in a wrong way. However, this is how I currently understand it. Feel free to correct me or give some extra explanation.
Currently working with: PrimeFaces 11.0.0 - JSF 3.0 - Glassfish 6.2.5.
IntelliJ 2022.1 Ultimate Edition

Software engineering student.

Melloware
Posts: 3716
Joined: 22 Apr 2013, 15:48

17 May 2022, 13:44

You should not need the OWASP Sanitizer. You only need that if using the TextEditor component.

See optional dependencies: https://primefaces.github.io/primefaces ... pendencies
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 29 guests