无法加载dataTable jsf

时间:2017-12-09 18:52:25

标签: java jsf-2

我试图将数据从java托管bean加载到jsf dataTable,如下所示:

package controller;

import java.io.Serializable;
import java.math.BigDecimal;

import javax.faces.bean.*;


@ManagedBean(name="accountController")
@SessionScoped
public class AccountController implements Serializable {

private static final long serialVersionUID = 1L;


private   List<Order> orderList = new ArrayList<Order>(); 

private void initList()
{

    orderList.add(new Order("A0001", "Intel CPU",
            new BigDecimal("700.00"), 1));
    orderList.add(new Order("A0001", "Intel CPU",
            new BigDecimal("700.00"), 1));
    orderList.add(new Order("A0002", "Intel CPU",
            new BigDecimal("700.00"), 1));
    orderList.add(new Order("A0003", "Intel CPU",
            new BigDecimal("700.00"), 1));
    orderList.add(new Order("A0005", "Intel CPU",
            new BigDecimal("700.00"), 1));
};

public List<Order> getOrderList() {
    initList();
    return orderList;
}

public static class Order{

    String orderNo;
    String productName;
    BigDecimal price;
    int qty;

    public Order(String orderNo, String productName,
                            BigDecimal price, int qty) {

        this.orderNo = orderNo;
        this.productName = productName;
        this.price = price;
        this.qty = qty;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {


        this.price = price;
    }


    public int getQty() {

        return qty;
    }


    public void setQty(int qty) {
        this.qty = qty;
    }


}
}

JSF页面就像这样:

    <!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://xmlns.jcp.org/jsf/html"
       xmlns:f="http://xmlns.jcp.org/jsf/core"
       xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

    <h:head>All records</h:head>
    <body>

    <h:dataTable cellpadding="2" cellspacing="2" border="1" value="#{accountController.orderList}" var="account">
        <h:column>
            <f:facet name="header">Username</f:facet>
            <h:outputText value="#{account.orderNo}"/> 
        </h:column>
        <h:column>
            <f:facet name="header">Email</f:facet>
            <h:outputText value="#{account.productName}"/> 
        </h:column>
        <h:column>
            <f:facet name="header">Fullname</f:facet>
            <h:outputText value="#{account.price}"/> 
        </h:column>
        <h:column>
            <f:facet name="header">ssdf</f:facet>
            <h:outputText value="#{account.qty}"/> 
        </h:column>

    </h:dataTable>

JSF库已添加到项目

即web.xml和faces-config.xml

&#13;
&#13;
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    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-facesconfig_2_2.xsd"
    version="2.2">

</faces-config>
&#13;
&#13;
&#13;

&#13;
&#13;
<?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" id="WebApp_ID" version="3.1">
  <display-name>JSF_EJB_JPA_CRUD_WebClient</display-name>
  <welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
  </welcome-file-list>
  <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>/faces/*</url-pattern>
  </servlet-mapping>
</web-app>
&#13;
&#13;
&#13;

structure of project

结果我一遍又一遍get

我做错了什么?我用eclipse或smth严重配置jsf? 作为使用glassfish 4的服务器

0 个答案:

没有答案