Ajax没有更新过滤的数据表

时间:2016-03-29 11:24:56

标签: ajax jsf-2 primefaces datatable

我正在经历这个问题,其中ajax没有从过滤的数据表中更新。 Primefaces版本是5.2 JSF 2.2 我正在使用一个selectEvent,它在对话框中显示行的详细信息。这很好用。但是,当我过滤数据表,然后尝试进行选择时,它无法正常工作。我试过下面的链接没有成功。 this this

代码是

<?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:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:o="http://omnifaces.org/ui">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="#{bundle.ListUtensilsTitle}"></h:outputText>
        </ui:define>
        <ui:define name="body">
            <h:form id="BookView1Form" >
                <p:messages id="messages" showSummary="true"  globalOnly="false"
                            showDetail="true" autoUpdate="true" closable="true" />
                <p:dataTable  value="#{bookingController.itemsBook}" var="book"
                             id="bookDetDT" widgetVar="bookDetTable"
                             tableStyle="width:auto"
                             style="word-wrap: break-word; padding-left: 15px;"
                             rows="10"
                             paginator="true"
                             paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                             rowsPerPageTemplate="5,10,20,30,40,50"
                             rowKey="#{book.bookingId}"
                             selectionMode="single" selection="#{bookingController.selectedBook}"
                             >
                    <p:ajax event="rowSelect"  listener="#{bookingController.onRowSelected}" 
                            update=":ViewDetForm bookDetDT"  oncomplete="PF('bookDetTable').filter();"/>
                        <p:ajax event="rowUnselect" />
                        <p:column filterBy="#{book.bookingId}" filterMatchMode="contains">
                        <f:facet name="header">
                                <h:outputText value="#{bundle.ListBookingDetailsTitle_bookingId}"/>
                        </f:facet>
                        <h:outputText value="#{book.bookingId}"/>
                    </p:column>
                    <p:column >
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListBookingDetailsTitle_guestId}"/>
                            </f:facet>
                            <h:outputText value="#{book.guestId}"/>
                    </p:column>


                    <p:column >
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListBookingDetailsTitle_bookingDate}"/>
                            </f:facet>
                            <h:outputText value="#{book.bookingDate}">
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputText>
                    </p:column>
                        <p:column >

                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListBookingDetailsTitle_timeSlotId}"/>
                            </f:facet>

                            <h:outputText value="#{book.timeSlotId.toString()}"/>
                        </p:column>
                    <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListBookingDetailsTitle_totalCharges}"/>
                            </f:facet>
                            <h:outputText value="#{book.totalCharges}"/>
                    </p:column>
                        <p:column >
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListBookingDetailsTitle_bookingStatus}"/>
                            </f:facet>

                            <h:outputText value="#{book.bookingStatus}"/>
                    </p:column>
                        <p:column width="100">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListBookingDetailsTitle_paymentId}"/>
                            </f:facet>
                        <h:outputText 
                            value="#{book.paymentId.paymentMode} #{book.paymentId.paymentDate} #{book.paymentId.paymentDetails}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Details"/>
                        </f:facet>

                        <p:dataTable value="#{book.itemsHalls}" var="halls" tableStyle="width:auto" >
                            <p:column >
                                <h:outputText value="#{halls.hallName}"/>
                            </p:column>
                            <p:column >
                                <h:outputText value="#{halls.venueId.venueName}"/>
                            </p:column>
                        </p:dataTable>
                    </p:column>
                  </p:dataTable>
          </h:form>
  <ui:include src="ViewBookingDetails.xhtml"/>
             </ui:define>
        </ui:composition>
    </html>

支持bean是

@ManagedBean(name = "bookingController")
@SessionScoped
public class BookingController implements Serializable {




    public List<BookingBean> getItemsBook() {
        itemsBook = new ArrayList<BookingBean>();
        itemsBookDet=ejbFacadeBookDet.findAll();

        for(BookingDetails bookTemp : itemsBookDet) {
            BookingBean selectedBookTemp = new BookingBean();
            selectedBookTemp.setBookingId(bookTemp.getBookingId());
            selectedBookTemp.setBookingDate(bookTemp.getBookingDate());
            selectedBookTemp.setTotalCharges(bookTemp.getTotalCharges());
            selectedBookTemp.setBookingStatus(bookTemp.getBookingStatus());
            selectedBookTemp.setBookingDesc(bookTemp.getBookingDesc());
            selectedBookTemp.setGuestId(bookTemp.getGuestId());
            selectedBookTemp.setPaymentId(bookTemp.getPaymentId());
            selectedBookTemp.setTimeSlotId(bookTemp.getTimeSlotId());
            itemsBook.add(selectedBookTemp);
        }


        for(BookingBean bk : itemsBook) {
            bk.setItemsHalls(ejbFacadeHB.findHallsListBookedForBookingID(bk.getBookingId()));
        }

        for(BookingBean bk : itemsBook) {
            if(bk.getBookingStatus().equals("CHECKOUT")) {

                bk.setItemsRefund(ejbFacadeBRF.findBookingRefundByBookID(bk.getBookingId()));
                //bk.getItemsRefund().setRefundUtensilsList(ejbFacadeBRF.findUtensilsList(bk.getItemsRefund().getRefundId()));
            }

        }



        //selectedBookDet = new BookingDetails();
        return itemsBook;
    }







    public String prepareView1() {
        selectedBookDet = null;
        selectedBook = new BookingBean();
        return "/booking/View1?faces-redirect=true";
    }

    public void onRowSelected(SelectEvent event) {

        selectedBook = (BookingBean)event.getObject();
        System.out.println(selectedBook.getBookingId());
        fakelist=new ArrayList<Integer>();
        fakelist.add(1);
        System.out.println("selectedBook = "+selectedBook.getBookingId());
        if(((BookingBean)event.getObject()).getBookingStatus().equals("CONFIRMED")) {
            selectedBookDet = ejbFacadeBookDet.find(((BookingBean)event.getObject()).getBookingId());
        } 

        /*
        FacesContext facesContext = FacesContext.getCurrentInstance();
        DataTable table;
        table = (DataTable)JsfUtil.findComponent(facesContext.getViewRoot(), "bookDetDT");
        table.resetValue();
        System.out.println(table.getClientId()+"sdgssfhdfh");
        table.reset();
        */
        RequestContext context = RequestContext.getCurrentInstance();
        context.execute("PF('viewBKDDialog').show();");


    }




    public void cancelBook(){

        switch(selectedBookDet.getBookingStatus()) {

            case "CONFIRMED" :

                selectedBookDet.setBookingStatus("CANCELLED");
                ejbFacadeBookDet.edit(selectedBookDet);
                itemsHB = ejbFacadeHB.findHallsBookedForBookingID(selectedBookDet.getBookingId());
                for(HallsBooked hallsBookedTemp : itemsHB) {

                    hallsBookedTemp.setHallsBookedDesc("CANCELLED");
                    ejbFacadeHB.edit(hallsBookedTemp);
                }

                JsfUtil.addSuccessMessage("Booking ID "+selectedBookDet.getBookingId()+" has been cancelled");
                itemsBook = null;
                selectedBookDet = null;
                break;

        }
    }

    private List<Integer> fakelist=null;

    public List<Integer> getFakelist() {
        return fakelist;
    }
}

任何人......请帮助我..

0 个答案:

没有答案