Page does not load Primefaces components

Asked

Viewed 1,978 times

1

My page is not loading the Primefaces components, in this case a datatable. The end result is thus both in Chrome and in the Eclipse navigator itself:

Lista de Marcas de Carro

Just follow my code:

listMarcas.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:p="http://primefaces.org/ui">
<h:body>
<h:form>
    <p:dataTable var="m" value="#{marcaBean.listaMarcas}">
          <p:column headerText="Id">
            <p:outputLabel value="#{m.idMarca}"></p:outputLabel>
        </p:column>
    <p:column headerText="Descrição">
            <p:outputLabel value="#{m.descMarca}"></p:outputLabel>
    </p:column> 
    <p:column headerText="Deletar"> 
        <h:commandLink value="Deletar" action="#{marcaBean.deletarMarca}">
        <f:setPropertyActionListener target="#{marcaBean.marca}" value="#{m}"></f:setPropertyActionListener>
        </h:commandLink>
    </p:column>
    </p:dataTable>
</h:form>
</h:body>
</html>

pom.xml

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>br.com</groupId>
  <artifactId>tesi2015</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>tesi2015 Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.33</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.6.Final</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.2.8-02</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.2.8-02</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>
    <dependency>
        <groupId>c3p0</groupId>
        <artifactId>c3p0</artifactId>
        <version>0.9.1.2</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.2</version>
    </dependency>

        <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>5.1</version>
        </dependency>
  </dependencies>
  <build>
    <finalName>tesi2015</finalName>
  </build>
</project>

web xml.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
  <display-name>tesi2015</display-name>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
</web-app>

I don’t know if I’m missing something, I’ve tried everything and I can’t load the table. How do I get this table to appear? What am I missing? Thanks.

  • I find it pertinent you edit your question and add the contents of your file web.xml.

  • Edited by @Electus

  • What apparently happens is that your application is blocking the CSS files that come along with the primefaces. Make sure you haven’t implemented a filter, authentication, something like...

  • I tried to add the layout and it didn’t work @Caffé

  • 1

    Ah, I think I remembered :-) You need a tag head because that’s where primefaces will add code to reference your libraries. Try it, before you open the tag <h:body>, add <h:head> <title>Título da página</title> </h:head>.

1 answer

2


In fact the Primefaces components were created, or you would have other symptoms. What occurred was that the styles were not applied.

The Primefaces adds references to your (css) style libraries in the tag head.

If he does not find this tag, he ends up not adding the references and his page is like this, with no style.

To solve the problem, simply add the tag head. Your code will look something like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Título da página (seção head necessária ao Primefaces)</title>
    </h:head>
    <h:body>
        <h:form>
            ...
        </h:form>
    </h:body>
</html>

Browser other questions tagged

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