数据表不显示值

Datatable does not show values

我有一个酒店对象列表,我想在 jsf 数据中显示每个对象的值table。我遇到的问题是,尽管 table 为每个酒店对象创建了一行,但未显示值。

datatable

这是我的酒店class:

public class Hotel {
private int id;
private String hotelname;
private String address;
private String information;
private int number_rooms_total;
private String pathimage;

public Hotel() {
}

public Hotel(int id, String hotelname, String address, String information, int number_rooms_total, String pathimage) {
    this.id = id;
    this.hotelname = hotelname;
    this.address = address;
    this.information = information;
    this.number_rooms_total = number_rooms_total;
    this.pathimage = pathimage;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getHotelname() {
    return hotelname;
}

public void setHotelname(String hotelname) {
    this.hotelname = hotelname;
}

public String getAddress() {
    return address;
}

public void setAddress(String address) {
    this.address = address;
}

public String getInformation() {
    return information;
}

public void setInformation(String information) {
    this.information = information;
}

public int getNumber_rooms_total() {
    return number_rooms_total;
}

public void setNumber_rooms_total(int number_rooms_total) {
    this.number_rooms_total = number_rooms_total;
}

public String getPathimage() {
    return pathimage;
}

public void setPathimage(String pathimage) {
    this.pathimage = pathimage;
}



@Override
public int hashCode() {
    int hash = 3;
    hash = 83 * hash + this.id;
    return hash;
}

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    final Hotel other = (Hotel) obj;
    if (this.id != other.id) {
        return false;
    }
    return true;
}

@Override
public String toString() {
    return "Hotel{" + "id=" + id + ", hotelname=" + hotelname + ", address=" + address + ", information=" + information + ", number_rooms_total=" + number_rooms_total + ", image=" + pathimage + '}';
  }
}

这是我的 JSF 页面:

<?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="http://www.w3.org/1999/xhtml"
   xmlns:h="http://xmlns.jcp.org/jsf/html"
   xmlns:f="http://xmlns.jcp.org/jsf/core">
 <h:head>
    <title>Facelet Title</title>
</h:head>
<h:body>
    <h2>List Hotels</h2>
    <legend>Hotels Form</legend>
    <h:form>
        <h:dataTable value="#{listHotels.hotels}" var="hotel" border="3">
            <h:column>
                <f:facet name="header">ID Hotel</f:facet>
                <h:outputText> value="#{hotel.id}"</h:outputText>
            </h:column>
            <h:column>
                <f:facet name="header">Name</f:facet>
                <h:outputText> value="#{hotel.hotelname}"</h:outputText>
            </h:column>
            <h:column>
                <f:facet name="header">Address</f:facet>
                <h:outputText> value="#{hotel.address}"</h:outputText>
            </h:column>
            <h:column>
                <f:facet name="header">Image</f:facet>
                <h:graphicImage value="#{hotel.pathimage}" />
            </h:column>
            <h:column>
                <f:facet name="header">New Booking</f:facet>
                <h:commandButton value="NewBooking" action="#{listHotels.newBooking(hotel)}"></h:commandButton>
            </h:column>
            <h:column>
                <f:facet name="header">List Booking</f:facet>
                <h:commandButton value="ListBooking" action="#{listHotels.listBookings(hotel)}"></h:commandButton>
            </h:column>
        </h:dataTable>
        <div id="message">
            == #{listHotels.message} ==
        </div>  
    </h:form>
</h:body>

这是我的 Bean Class:

@ManagedBean
@SessionScoped
public class ListHotels implements Serializable {

private Database db = null;
private String message = null;
private ArrayList<Hotel> hotels = new ArrayList<>();
private Hotel currHotel;

public ListHotels() {
    try {
        db = Database.getInstance();
    } catch (Exception ex) {
        System.out.println("ex: " + ex.getMessage());
    }
}

public ArrayList<Hotel> getHotels() {
    System.out.println("hallofff");

    hotels.clear();
    try {
        hotels = db.getAllHotels();
        System.out.println(hotels);
        message = "all hotels listed";
        System.out.println("message  " + message);
    } catch (Exception ex) {
        message = "ex :" + ex.getMessage();
    }

    return hotels;
}

public void setHotels(ArrayList<Hotel> hotels) {
    this.hotels = hotels;
}

public String newBooking(Hotel h) {
    String retUrl = "NewBooking";
    currHotel = h;
    return retUrl;
}

public String listBookings(Hotel h) {
    String retUrl = "ListBookings";
    currHotel = h;
    return retUrl;
}

public String getMessage() {
    return message;
}

public void setMessage(String message) {
    this.message = message;
}

public Hotel getCurrHotel() {
    return currHotel;
}

 public void setCurrHotel(Hotel currHotel) {
    this.currHotel = currHotel;
 }
}

酒店方法=db.getAllHotels(); returns 我的 sql 数据库中的所有酒店。我已经检查过并且我的 arraylist 中的值是正确的。所以我真的不知道为什么我会遇到这个问题......这看起来很简单但不可能。

前 3 列的 outputText 标签似乎有误。
> 在开始标签上的位置不正确。

<h:outputText> value="#{hotel.id}"</h:outputText>

改为

<h:outputText value="#{hotel.id}" />

再检查一次。