Adding JSF in java project

Asked

Viewed 416 times

1

I created a Maven project in Intellij IDEA 2016.2, defined it as a Web Application, and later installed JSF.

Before installing the JSF the framework added the index.jsp file, which works normally, after adding the JSF created a new file called index.xhtml, but when trying to open it the Tomcat returns me:

HTTP Status 404 - type Status report

message

Description The requested Resource is not available.

Apache Tomcat/9.0.0.M11

pom.xml

<?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>br.com.blue</groupId>
    <artifactId>Blue</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <java.version>1.8</java.version>
        <hibernate.version>5.2.4.Final</hibernate.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <javax.servlet.version>3.1.0</javax.servlet.version>
        <jsf.api.version>2.2.13</jsf.api.version>
        <jsf.impl.version>2.2.9</jsf.impl.version>
        <jstl.version>1.2</jstl.version>
    </properties>


    <dependencies>
        <!-- HIBERNATE -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency>

        <!-- JAVAX SERVLET -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${javax.servlet.version}</version>
        </dependency>

        <!-- JSF -->
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>${jsf.api.version}</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>${jsf.impl.version}</version>
        </dependency>

        <!-- JSTL -->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>${jstl.version}</version>
        </dependency>

    </dependencies>
</project>

inserir a descrição da imagem aqui

  • how so, you installed JSF? publish your POM.xml and print the structure of your project, including your LIB.

  • Marcos, I added the requested information.

  • the answer may help.

1 answer

1


Well, I don’t understand the version of your JSF dependency. Try replacing it with the following (or you can choose another one from the Maven repository).

<dependency>
    <groupId>javax.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.1</version>
</dependency>

Another thing I noticed is that if it’s a Maven project, your views shouldn’t be in the folder webapp?

Following the directory logic:

  • src/main/java: package-organized application source code;
  • src/main/Resources: resources the application needs;
  • src/main/webapp: directory for web applications, web.xml, images,
    HTML and XHTM’s;
  • src/test/java: unit tests;

Also check if in the configuration file web.xml is this way:

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

The *.xhtml says that the index to be searched will be the index.xhtml and not the .jsp

PS - The JSF -Java Server Faces not installed, it is only a specification. It is in charge of the implementations, for example Mojarra and Myfaces, make available their libraries that meet this JCP standard.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.