DataTable not displaying cell values

UI Components for JSF
Post Reply
azzuwan
Posts: 1
Joined: 21 Jul 2011, 06:58

21 Jul 2011, 07:23

Hi,

I added data to an array list in the constructor of my backing bean. The data table display the correct number of rows but the values in the cells are filled with zeros and empty strings.

My backing bean.

Code: Select all

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.trivio.oms.mbeans;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.inject.Named;
import javax.enterprise.context.Dependent;

@Named(value = "orderViewBean")
@Dependent
public class OrderViewBean {

    private List<Order> orderList;
    private Order selectedOrder;
    private Order[] selectedOrders;


    public OrderViewBean() {
        
        orderList = new ArrayList<Order>();
        for (int i = 0; i < 30; i++) {
            Order o = new Order(i, new Date(), new Date(), "GrowBio Premium", 10, 2200, "new", "Selangor");            
            orderList.add(o);
        }
    }

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

    public void setOrderList(List<Order> orderList) {
        this.orderList = orderList;
    }

    public Order getSelectedOrder() {
        return selectedOrder;
    }

    public void setSelectedOrder(Order selectedOrder) {
        this.selectedOrder = selectedOrder;
    }

    public Order[] getSelectedOrders() {
        return selectedOrders;
    }

    public void setSelectedOrders(Order[] selectedOrders) {
        this.selectedOrders = selectedOrders;
    }
}


This is the Order bean:

Code: Select all

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.trivio.oms.mbeans;

import java.util.Date;
import javax.inject.Named;
import javax.enterprise.context.Dependent;
import javax.faces.bean.ViewScoped;

@Named(value = "order")
@Dependent

public class Order {
    private int orderID;
    private Date orderDate;
    private Date requestDate;
    private String product;
    private int quantity;
    private float price;
    private String status;
    private String state;

    public Order() {

    }

    public Order(int orderId, Date orderDate, Date requestDate, String product, int quantity, float price, String status, String state) {
        this.orderID = orderId;
        this.orderDate = orderDate;
        this.requestDate = requestDate;
        this.product = product;
        this.quantity = quantity;
        this.price = price;
        this.status = status;
        this.state = state;
    }
    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public int getOrderID() {
        return orderID;
    }

    public void setOrderID(int orderId) {
        this.orderID = orderId;
    }

    public Date getOrderDate() {
        return orderDate;
    }

    public void setOrderDate(Date orderDate) {
        this.orderDate = orderDate;
    }

    public Date getRequestDate() {
        return requestDate;
    }

    public void setRequestDate(Date requestDate) {
        this.requestDate = requestDate;
    }

    public String getProduct() {
        return product;
    }

    public void setProduct(String product) {
        this.product = product;
    }

  
    public int getQuantity() {
        return quantity;
    }

  
    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

  
    public float getPrice() {
        return price;
    }

  
    public void setPrice(float price) {
        this.price = price;
    }

  
    public String getStatus() {
        return status;
    }

  
    public void setStatus(String status) {
        this.status = status;
    }
}

The Datatable:

Code: Select all

<p:dataTable var="order" value="#{orderViewBean.orderList}" id="dt1"
                                         paginator="true" scrollable="false" rows="10">
                                <f:facet name="header">
                                    Latest Orders
                                </f:facet>
                                <p:column style="width:100px" headerText="Order ID">                                   
                                    <h:outputText value="#{order.orderID}"/>                                    
                                </p:column>
                                <p:column headerText="Product">
                                    <h:outputText value="#{order.product}" />
                                </p:column>
                                <p:column headerText="Qty" style="width:50px">
                                    <h:outputText value="#{order.quantity}" />
                                </p:column>
                                <p:column headerText="Price" style="width:80px">
                                    <h:outputText value="#{order.price}" />
                                </p:column>
                            </p:dataTable>
All numerical columns show 0 and string columns are empty. What did I do wrong?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 31 guests