jsfprimefaces

Java Primefaces Dependency Managed Bean


I have been suffering and trying many times to create a really simple project with primefaces from tutorials. I have done a lot of them and all of them don't work for me.

They all insert only one dependency:

<dependencies>
       <dependency>
           <groupId>org.primefaces</groupId>
           <artifactId>primefaces</artifactId>
           <version>14.0.1</version>
       </dependency>
</dependencies> 

Even when I inject it I do not have access to those 2 annotations that all tutorials use with only primefaces dependency and they do not mention about any other dependencies.

Also when I create .xhtml with those namespaces, the last two:

xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"

do not work for me. They are displaying this error:

Resource registered by this uri is not recognized (Settings | Languages & Frameworks | Schemas and DTDs)

What am I doing wrong? This is my code:

@ManagedBean
@RequestedScope
public class Beanek {
    public void metoda() {
        System.out.println("Kliknięto przycisk PrimeFaces!");
    }
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>PrimeFaces Example</title>
</h:head>
<h:body>
    <h:form>
        <p:commandButton value="Kliknij mnie" actionListener="#{bean.metoda}" />
    </h:form>
</h:body>
</html>
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>doWydupienia</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>20</maven.compiler.source>
        <maven.compiler.target>20</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>14.0.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>19</source>
                    <target>19</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Solution

  • You don't need to do any of that PrimeFaces has a simple ready to go out of the box sample project for you. BTW ManagedBean is dead and has been for a long time there is no need for it anymore. Just use CDI. Here is PrimeFaces Test project to get you started: https://github.com/primefaces/primefaces-test

    Also here is a great BalusC tutorial for getting started with JSF: https://balusc.omnifaces.org/2020/04/jsf-23-tutorial-with-eclipse-maven.html