Jsf 为什么我的Java服务器没有填充HTML数据表?

Jsf 为什么我的Java服务器没有填充HTML数据表?,jsf,Jsf,我按照一本书中的说明创建JSF网页。创建数组列表的init()方法。此列表填充数据表,但网页上没有显示任何内容。我在init方法中放了一条日志消息,没有显示任何消息 编辑: Java 1.8.0Þ、Payara 5.193.1、NetBeans 8.2 javaee-web-api-8.0,javax.faces-2.2.7,javaee-approved-api-7.0 index.html <?xml version='1.0' encoding='UTF-8' ?> <!

我按照一本书中的说明创建JSF网页。创建数组列表的init()方法。此列表填充数据表,但网页上没有显示任何内容。我在init方法中放了一条日志消息,没有显示任何消息

编辑: Java 1.8.0Þ、Payara 5.193.1、NetBeans 8.2

javaee-web-api-8.0,javax.faces-2.2.7,javaee-approved-api-7.0

index.html

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE xhtml PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [<!ENTITY copy "&#169;">]>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Books</title>
        <h:outputStylesheet library="css" name="books.css"/>
    </h:head>
    <h:body>
        <div id="wrapper">
            <header>
                <h1>Michael's book list</h1>
            </header>
            <main>
                <h1>Edit categories</h1>
                <h:form>
                    <h:dataTable value="#{categoryEditor.categories}"
                                 var="cat">
                        <h:column>
                            <h:commandLink
                                action="#{categoryEditor.deleteCategory(cat)}">
                                <h:graphicImage alt="delete"
                                                name="Delete.png"
                                                library="icon/small"
                                                title="delete"/>
                            </h:commandLink>
                        </h:column>
                        <h:column>
                            <h:inputText value="#{cat.name}"/>
                        </h:column>
                    </h:dataTable>
                    <h:commandLink styleClass="button"
                                   value="Add category"
                                   action="#{categoryEditor.addCategory}"/>
                    <h:commandButton styleClass="button"
                                     value="Save"
                                     action="#{categoryEditor.save}"/>
                </h:form>
            </main>
            <nav>
                This is the Navigation
            </nav>
            <footer>
                &copy; Michael Muller <!-- &copy refers to the copyright sign 
                HTML5 doesn't know such entities, so doctype must be enhanced-->

                <h:outputLink value="http://blog.mueller-bruehl.de">
                    Michael's Blog
                </h:outputLink>

                <h:link value="About" outcome="index.xhtml"/>
            </footer>
        </div>
    </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>us.potato</groupId>
    <artifactId>Books</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>Books</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.faces</artifactId>
            <version>2.2.7</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>8.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>
<web-app version="4.0" 
         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_4_0.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>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>\
<?xml version="1.0" encoding="UTF-8"?>
    <properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
        <org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.7-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
        <org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>gfv3ee6</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
        <org-netbeans-modules-projectapi.jsf_2e_language>Facelets</org-netbeans-modules-projectapi.jsf_2e_language>
    </properties>
</project-shared-configuration>

书
迈克尔的书单
编辑类别
这是导航
&抄袭;迈克尔·穆勒
迈克尔的博客
CategoryEditor.java

package us.potato.books;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named
@SessionScoped
public class CategoryEditor implements Serializable{
    private static final long serialVersionUID = 1L;
    private static final Logger _logger = Logger.getLogger("CategoryEditor");

    @PostConstruct
    private void init() {
        _categories = new ArrayList<>();
        _categories.add(new Category(){{setId(1); setName("Java");}});
        _categories.add(new Category(){{setId(2); setName("Web");}});
        _logger.log(Level.INFO, "Categories initialized");
    }

    private List<Category> _categories;

    public List<Category> getCategories() {
        return _categories;
    }

    public void setCategories(List<Category> categories) {
        _categories = categories;
    }

    public String addCategory(){
        _categories.add(new Category());
        return "";
    }

    public String deleteCategory(Category category){
        _categories.remove(category);
        return "";
    }

    public String save(){
        String categories = "";
        for (Category category : _categories){
            if(!category.getName().isEmpty()){
                if (categories.length() > 0){
                    categories += ", ";
                }
                categories += category;
            }
        }
        _logger.log(Level.INFO, "Save categories: {0}", categories);
        return "";
    }
}
package us.potato.books;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named
@SessionScoped
public class CategoryEditor implements Serializable{
    private static final long serialVersionUID = 1L;
    private static final Logger _logger = Logger.getLogger("CategoryEditor");

    @PostConstruct
    private void init() {
        _categories = new ArrayList<>();
        _categories.add(new Category(){{setId(1); setName("Java");}});
        _categories.add(new Category(){{setId(2); setName("Web");}});
        _logger.log(Level.INFO, "Categories initialized");
    }

    private List<Category> _categories;

    public List<Category> getCategories() {
        return _categories;
    }

    public void setCategories(List<Category> categories) {
        _categories = categories;
    }

    public String addCategory(){
        _categories.add(new Category());
        return "";
    }

    public String deleteCategory(Category category){
        _categories.remove(category);
        return "";
    }

    public String save(){
        String categories = "";
        for (Category category : _categories){
            if(!category.getName().isEmpty()){
                if (categories.length() > 0){
                    categories += ", ";
                }
                categories += category;
            }
        }
        _logger.log(Level.INFO, "Save categories: {0}", categories);
        return "";
    }
}
package us.potato.books;
导入java.io.Serializable;
导入java.util.ArrayList;
导入java.util.List;
导入java.util.logging.Level;
导入java.util.logging.Logger;
导入javax.annotation.PostConstruct;
导入javax.enterprise.context.SessionScoped;
导入javax.inject.Named;
@命名
@会议范围
公共类CategoryEditor实现可序列化{
私有静态最终长serialVersionUID=1L;
私有静态最终记录器_Logger=Logger.getLogger(“类别编辑器”);
@施工后
私有void init(){
_categories=newarraylist();
_add(newcategory(){{setId(1);setName(“Java”);}});
_添加(新的Category(){{setId(2);setName(“Web”);});
_logger.log(Level.INFO,“类别已初始化”);
}
私人名单(类别),;
公共列表getCategories(){
返回(u)类别;;
}
公共类别(列出类别){
_类别=类别;
}
公共字符串addCategory(){
_类别。添加(新类别());
返回“”;
}
公共字符串deleteCategory(类别){
_类别。删除(类别);
返回“”;
}
公共字符串保存(){
字符串类别=”;
对于(类别:_类别){
如果(!category.getName().isEmpty()){
if(categories.length()>0){
类别+=“,”;
}
类别+=类别;
}
}
_logger.log(Level.INFO,“保存类别:{0}”,类别);
返回“”;
}
}
Category.java

package us.potato.books;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named
@SessionScoped
public class CategoryEditor implements Serializable{
    private static final long serialVersionUID = 1L;
    private static final Logger _logger = Logger.getLogger("CategoryEditor");

    @PostConstruct
    private void init() {
        _categories = new ArrayList<>();
        _categories.add(new Category(){{setId(1); setName("Java");}});
        _categories.add(new Category(){{setId(2); setName("Web");}});
        _logger.log(Level.INFO, "Categories initialized");
    }

    private List<Category> _categories;

    public List<Category> getCategories() {
        return _categories;
    }

    public void setCategories(List<Category> categories) {
        _categories = categories;
    }

    public String addCategory(){
        _categories.add(new Category());
        return "";
    }

    public String deleteCategory(Category category){
        _categories.remove(category);
        return "";
    }

    public String save(){
        String categories = "";
        for (Category category : _categories){
            if(!category.getName().isEmpty()){
                if (categories.length() > 0){
                    categories += ", ";
                }
                categories += category;
            }
        }
        _logger.log(Level.INFO, "Save categories: {0}", categories);
        return "";
    }
}
package us.potato.books;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named
@SessionScoped
public class CategoryEditor implements Serializable{
    private static final long serialVersionUID = 1L;
    private static final Logger _logger = Logger.getLogger("CategoryEditor");

    @PostConstruct
    private void init() {
        _categories = new ArrayList<>();
        _categories.add(new Category(){{setId(1); setName("Java");}});
        _categories.add(new Category(){{setId(2); setName("Web");}});
        _logger.log(Level.INFO, "Categories initialized");
    }

    private List<Category> _categories;

    public List<Category> getCategories() {
        return _categories;
    }

    public void setCategories(List<Category> categories) {
        _categories = categories;
    }

    public String addCategory(){
        _categories.add(new Category());
        return "";
    }

    public String deleteCategory(Category category){
        _categories.remove(category);
        return "";
    }

    public String save(){
        String categories = "";
        for (Category category : _categories){
            if(!category.getName().isEmpty()){
                if (categories.length() > 0){
                    categories += ", ";
                }
                categories += category;
            }
        }
        _logger.log(Level.INFO, "Save categories: {0}", categories);
        return "";
    }
}
package us.potato.books;
导入java.io.Serializable;
导入java.util.ArrayList;
导入java.util.List;
导入java.util.logging.Level;
导入java.util.logging.Logger;
导入javax.annotation.PostConstruct;
导入javax.enterprise.context.SessionScoped;
导入javax.inject.Named;
@命名
@会议范围
公共类CategoryEditor实现可序列化{
私有静态最终长serialVersionUID=1L;
私有静态最终记录器_Logger=Logger.getLogger(“类别编辑器”);
@施工后
私有void init(){
_categories=newarraylist();
_add(newcategory(){{setId(1);setName(“Java”);}});
_添加(新的Category(){{setId(2);setName(“Web”);});
_logger.log(Level.INFO,“类别已初始化”);
}
私人名单(类别),;
公共列表getCategories(){
返回(u)类别;;
}
公共类别(列出类别){
_类别=类别;
}
公共字符串addCategory(){
_类别。添加(新类别());
返回“”;
}
公共字符串deleteCategory(类别){
_类别。删除(类别);
返回“”;
}
公共字符串保存(){
字符串类别=”;
对于(类别:_类别){
如果(!category.getName().isEmpty()){
if(categories.length()>0){
类别+=“,”;
}
类别+=类别;
}
}
_logger.log(Level.INFO,“保存类别:{0}”,类别);
返回“”;
}
}
pom.xml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE xhtml PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [<!ENTITY copy "&#169;">]>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Books</title>
        <h:outputStylesheet library="css" name="books.css"/>
    </h:head>
    <h:body>
        <div id="wrapper">
            <header>
                <h1>Michael's book list</h1>
            </header>
            <main>
                <h1>Edit categories</h1>
                <h:form>
                    <h:dataTable value="#{categoryEditor.categories}"
                                 var="cat">
                        <h:column>
                            <h:commandLink
                                action="#{categoryEditor.deleteCategory(cat)}">
                                <h:graphicImage alt="delete"
                                                name="Delete.png"
                                                library="icon/small"
                                                title="delete"/>
                            </h:commandLink>
                        </h:column>
                        <h:column>
                            <h:inputText value="#{cat.name}"/>
                        </h:column>
                    </h:dataTable>
                    <h:commandLink styleClass="button"
                                   value="Add category"
                                   action="#{categoryEditor.addCategory}"/>
                    <h:commandButton styleClass="button"
                                     value="Save"
                                     action="#{categoryEditor.save}"/>
                </h:form>
            </main>
            <nav>
                This is the Navigation
            </nav>
            <footer>
                &copy; Michael Muller <!-- &copy refers to the copyright sign 
                HTML5 doesn't know such entities, so doctype must be enhanced-->

                <h:outputLink value="http://blog.mueller-bruehl.de">
                    Michael's Blog
                </h:outputLink>

                <h:link value="About" outcome="index.xhtml"/>
            </footer>
        </div>
    </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>us.potato</groupId>
    <artifactId>Books</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>Books</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.faces</artifactId>
            <version>2.2.7</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>8.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>
<web-app version="4.0" 
         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_4_0.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>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>\
<?xml version="1.0" encoding="UTF-8"?>
    <properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
        <org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.7-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
        <org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>gfv3ee6</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
        <org-netbeans-modules-projectapi.jsf_2e_language>Facelets</org-netbeans-modules-projectapi.jsf_2e_language>
    </properties>
</project-shared-configuration>

4.0.0
美国马铃薯
书
1.0-快照
战争
书
${project.build.directory}/project
UTF-8
玻璃鱼
javax.faces
2.2.7
爪哇
javaeewebapi
8
假如
org.apache.maven.plugins
maven编译器插件
3.1
1.7
1.7
${annowed.dir}
org.apache.maven.plugins
maven战争插件
2.3
假的
org.apache.maven.plugins
maven依赖插件
2.6
验证
复制
${annowed.dir}
真的
爪哇
javaee认可的api
7