0

生成表格后,我无法在对话框中显示我的属性详细信息。结果已显示,但所选行未显示在对话框中。我已经从 primefaces 展示案例中接管了这个例子。

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>TODO supply a title</title>
        <h:outputStylesheet library="css" name="styles.css"  />     
    </h:head>

    <h:body>
        Dear customer! 
        <li>#{userDataManager.displayHotelTypeChoice(userDataManager.hotelChoice)}
        </li> 
        <li>#{userDataManager.displayPaxChoice(userDataManager.pax)}
        </li> 
        <li>You have chosen to check in : #{userDataManager.displayCheckinDate(userDataManager.checkinDate)}
        </li> 
        <li>You have chosen to check out : #{userDataManager.displayCheckoutDate(userDataManager.checkoutDate)}
        </li>
        <li>Total Days of Stay : #{userDataManager.countNightsBetween(userDataManager.checkinDate,userDataManager.checkoutDate)}
        </li>
        <li>Total Nights of Stay : #{userDataManager.nights}
        </li>
        <br>
        </br>
        <h:form id="form">

            <p:dataTable id="hotels" var="room" value="#{propertyDataTable.searchByHotelType
                                                         (userDataManager.hotelChoice, userDataManager.pax)}"
                         rowKey="#{room.propertyID}" 
                         selection="#{propertyDataTable.selectedProperty}"
                         selectionMode="single"
                         resizableColumns="true">
                <f:facet name="header">
                    #{userDataManager.displayHotelTypeChoice(userDataManager.hotelChoice)}<br></br>
                    Please select only one choice
                </f:facet>

                <p:column headerText="Property ID" >
                    #{room.propertyID}
                </p:column>

                <p:column headerText="Accommodation" >
                    #{room.accommodation}
                </p:column>

                <p:column headerText="Pax" >
                    #{room.pax}
                </p:column>                

                <p:column headerText="Stars" >
                    #{room.stars}
                </p:column> 

                <p:column headerText="Type" >
                    #{room.type}
                </p:column>            

                <f:facet name="footer">  
                    In total there are #{propertyDataTable.listSize(propertyDataTable.
                                         searchByHotelType(userDataManager.hotelChoice, 
                                         userDataManager.pax))} hotels.  
                    <p:commandButton id="viewButton" value="View" icon="ui-icon-search"  
                                     update=":form:display" oncomplete="hotelDialog.show()">  
                    </p:commandButton>
                </f:facet>  

            </p:dataTable>

            <p:dialog id="dialog" header="Hotel Detail" widgetVar="hotelDialog" resizable="false"  
                      width="200" showEffect="clip" hideEffect="fold">  

                <h:panelGrid id="display" columns="2" cellpadding="4">  

                    <f:facet name="header">  
                        <!--<p:graphicImage value="/resources/images/#{propertyDataTable.selectedProperty.type}.jpg"/>-->                        
                        <p:graphicImage value="/resources/images/Grand.jpg"/>
                    </f:facet>  

                    <h:outputText value="Accommodation:" />  
                    <h:outputText value="#{propertyDataTable.selectedProperty.accommodation }" />    

                    <h:outputText value="Feature:" />  
                    <h:outputText value="#{propertyDataTable.selectedProperty.feature}" />  

                    <h:outputText value="Stars:" />  
                    <h:outputText value="#{propertyDataTable.selectedProperty.stars}" />  

                </h:panelGrid>  
            </p:dialog>  
        </h:form>

        <br></br>
        <br></br>
        <h:commandButton value="Book" 
                         action="#{navigationController.showPage()}" >
            <f:param name="page" value="book" />
        </h:commandButton>
        <br></br>
        <h:commandButton value="HOME" 
                         action="#{navigationController.showPage()}" >
            <f:param name="page" value="home" />
        </h:commandButton>

    </h:body>
</html>
package dataTable;

import irms.entity.accommodation.Property;
import irms.entity.accommodation.Room;
import irms.session.accommodation.PropertySession;
import irms.session.accommodation.ReservationSession;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author Lawrence
 */
@ManagedBean(name = "propertyDataTable")
@ViewScoped
public class PropertyDataTable implements Serializable{

    @EJB
    private ReservationSession reservationSession;
    @EJB
    private PropertySession propertySession;

    private List<Property> propertyList;
    private int choice;

    private Property selectedProperty;

     private List<Room> list = new ArrayList();

    public PropertyDataTable() {
    }

    public List<Property> getAllRooms() {
        return reservationSession.getAllRooms();
    }

    public List<Property> searchByHotelType(String hotelType, Integer pax) {
        this.propertyList = propertySession.searchByHotelType(hotelType, pax);
        return propertyList;
    }


    public int listSize(List<Property> list){
        return list.size();
    }

    public Room getRoom(String propertyID, Integer roomID) {
        return propertySession.findRoom(propertyID, roomID);
    }

    public List<Room> getRoomList(String propertyID){
        return propertySession.getRoomList(propertyID);
    }

    public ReservationSession getReservationSession() {
        return reservationSession;
    }

    public void setReservationSession(ReservationSession reservationSession) {
        this.reservationSession = reservationSession;
    }

    public PropertySession getPropertySession() {
        return propertySession;
    }

    public void setPropertySession(PropertySession propertySession) {
        this.propertySession = propertySession;
    }

    public List<Property> getPropertyList() {
        return propertyList;
    }

    public void setPropertyList(List<Property> propertyList) {
        this.propertyList = propertyList;
    }

    public int getChoice() {
        return choice;
    }

    public void setChoice(int choice) {
        this.choice = choice;
    }

    public Property getSelectedProperty() {
        return selectedProperty;
    }

    public void setSelectedProperty(Property selectedProperty) {
        this.selectedProperty = selectedProperty;
    }

    public List<Room> getList() {
        return list;
    }

    public void setList(List<Room> list) {
        this.list = list;
    }
}
4

1 回答 1

0

您必须ActionListener在 viewButton 中添加commandButton 更改xhtml页面,如下所示:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>TODO supply a title</title>
        <h:outputStylesheet library="css" name="styles.css"  />     
    </h:head>

    <h:body>
        Dear customer! 
        <li>#{userDataManager.displayHotelTypeChoice(userDataManager.hotelChoice)}
        </li> 
        <li>#{userDataManager.displayPaxChoice(userDataManager.pax)}
        </li> 
        <li>You have chosen to check in : #{userDataManager.displayCheckinDate(userDataManager.checkinDate)}
        </li> 
        <li>You have chosen to check out : #{userDataManager.displayCheckoutDate(userDataManager.checkoutDate)}
        </li>
        <li>Total Days of Stay : #{userDataManager.countNightsBetween(userDataManager.checkinDate,userDataManager.checkoutDate)}
        </li>
        <li>Total Nights of Stay : #{userDataManager.nights}
        </li>
        <br>
        </br>
        <h:form id="form">

            <p:dataTable id="hotels" var="room" value="#{propertyDataTable.searchByHotelType
                                                         (userDataManager.hotelChoice, userDataManager.pax)}"
                         rowKey="#{room.propertyID}" 
                                                resizableColumns="true">
                <f:facet name="header">
                    #{userDataManager.displayHotelTypeChoice(userDataManager.hotelChoice)}<br></br>
                    Please select only one choice
                </f:facet>

                <p:column headerText="Property ID" >
                    #{room.propertyID}
                </p:column>

                <p:column headerText="Accommodation" >
                    #{room.accommodation}
                </p:column>

                <p:column headerText="Pax" >
                    #{room.pax}
                </p:column>                

                <p:column headerText="Stars" >
                    #{room.stars}
                </p:column> 

                <p:column headerText="Type" >
                    #{room.type}
                </p:column>            

                <f:facet name="footer">  
                    In total there are #{propertyDataTable.listSize(propertyDataTable.
                                         searchByHotelType(userDataManager.hotelChoice, 
                                         userDataManager.pax))} hotels.  
                    <p:commandButton id="viewButton" value="View" icon="ui-icon-search"  
                                     update=":form:display" oncomplete="hotelDialog.show()">  
<f:setPropertyActionListener value="#{room}" target="#{propertyDataTable.selectedProperty}" />
                    </p:commandButton>
                </f:facet>  

            </p:dataTable>

            <p:dialog id="dialog" header="Hotel Detail" widgetVar="hotelDialog" resizable="false"  
                      width="200" showEffect="clip" hideEffect="fold">  

                <h:panelGrid id="display" columns="2" cellpadding="4">  

                    <f:facet name="header">  
                        <!--<p:graphicImage value="/resources/images/#{propertyDataTable.selectedProperty.type}.jpg"/>-->                        
                        <p:graphicImage value="/resources/images/Grand.jpg"/>
                    </f:facet>  

                    <h:outputText value="Accommodation:" />  
                    <h:outputText value="#{propertyDataTable.selectedProperty.accommodation }" />    

                    <h:outputText value="Feature:" />  
                    <h:outputText value="#{propertyDataTable.selectedProperty.feature}" />  

                    <h:outputText value="Stars:" />  
                    <h:outputText value="#{propertyDataTable.selectedProperty.stars}" />  

                </h:panelGrid>  
            </p:dialog>  
        </h:form>

        <br></br>
        <br></br>
        <h:commandButton value="Book" 
                         action="#{navigationController.showPage()}" >
            <f:param name="page" value="book" />
        </h:commandButton>
        <br></br>
        <h:commandButton value="HOME" 
                         action="#{navigationController.showPage()}" >
            <f:param name="page" value="home" />
        </h:commandButton>

    </h:body>
</html>
于 2013-09-10T11:25:36.580 回答