首页 > 解决方案 > JSF 问题。XML 文件似乎没有任何与之关联的样式信息

问题描述

我在 java jsf 中启动,我创建了一个简单的 xhtml 以在 localhost 中显示表,但我收到此错误“此 XML 文件似乎没有任何与之关联的样式信息。文档树如下所示。” 我没有任何想法来解决这个问题。我的项目很简单,只是显示一个带有mysql表记录的jsf表。下面是我的项目。

Especialidade:
      package itc.itcsystems.beans;

public class Especialidade
{
    private int ID;
    private String Especialidade;

    public Especialidade()
    {

    }
    
    public Especialidade(int ID, String Especialidade)
    {
        this.ID = ID;
        this.Especialidade = Especialidade;
    }
    
    public int getID() {
        return ID;
    }

    public void setID(int ID) {
        this.ID = ID;
    }

    public String getEspecialidade() {
        return Especialidade;
    }

    public void setEspecialidade(String Especialidade) {
        this.Especialidade = Especialidade;
    }
}

    
EspecialidadesDAO:
    package itc.itcsystems.beans;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class EspecialidadesDAO implements Serializable
{
    public Connection conectar;
    public Connection conectardb;
    
    private static final long serialVersionUID = 1L;
    
    public EspecialidadesDAO()
    {
        conectar = new Conectar_Banco_W00().getConnection();
        
    }
    
    public List<Especialidade> getEspecialidade()
    {
        String LISTHemog = "SELECT Especialidade "
                + "FROM Tabela_Especialidades_Medicas";
       
        Connection conexao = null;
        PreparedStatement pstm = null;
        ResultSet rs = null;
        ArrayList<Especialidade> medico = new ArrayList<Especialidade>();
        
        try
        {            
            conexao = new Conectar_Banco_W00().getConnection();
            pstm = conexao.prepareStatement(LISTHemog);
            
            rs = pstm.executeQuery();
            
            while (rs.next())                
            {
                Especialidade especialidade = new Especialidade();
                especialidade.setEspecialidade(rs.getString("Especialidade"));
                
                medico.add(especialidade);
            }
            Conectar_Banco_W00.fecharConexao(conexao, pstm, rs);
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        return medico;
    }
    
}

TabelaEspecialidade:
   <?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml"
    xmlns:f="https://java.sun.com/jsf/core"
    xmlns:h="https://java.sun.com/jsf/html">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <h:dataTable value="#{EspecialidadesDAO.getEspecialidade}" var="tipo" border="2">
            <h:column>
                <f:facet name="header">Escolha especialidade</f:facet>
                #{EspecialidadesDAO.tipo}
            </h:column>
        </h:dataTable>
    </h:body>
</html>
    
Dependencies:
<?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>itc.itcsystems</groupId>
    <artifactId>ITC_Systems_ClientesMedicos</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>ITC_Systems_ClientesMedicos</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.2.20</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.sun.faces/jsf-impl -->
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.20</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/jstl -->
        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>   

The result of execution:
    This XML file does not appear to have any style information associated with it. The document tree is shown below.
<html xmlns="https://www.w3.org/1999/xhtml" xmlns:f="https://java.sun.com/jsf/core" xmlns:h="https://java.sun.com/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:dataTable value="#{EspecialidadesDAO.getEspecialidade}" var="tipo" border="2">
<h:column>
<f:facet name="header">Escolha especialidade</f:facet>
#{EspecialidadesDAO.tipo}
</h:column>
</h:dataTable>
</h:body>
</html>```        

Thanks in advance.

标签: jsf

解决方案


推荐阅读