簡體   English   中英

如何從Back bean更新jsf數據表

[英]How to update jsf datatable from back bean

我有一個表單,用戶應輸入一些值以從Web服務獲取一些信息。 首先,用戶填寫表格,然后在單擊請求按鈕時調用Web服務。 到這里為止,一切都很好。 但是隨着Web服務返回信息,我必須用新數據重新渲染數據表。 這是我的頁面:

<h:body>
    <h:form id="formCus">
        <h:outputLabel value="Müşteri Tipi: *"/>
        <p:selectOneMenu id="customerType" value="#{customerService.musteriTipi}" style="width: 39%">
            <f:selectItem itemLabel="" itemValue=" " />
            <f:selectItem itemLabel="Bireysel" itemValue="BIREYSEL" />
            <f:selectItem itemLabel="Tüzel" itemValue="TUZEL" />
            <f:selectItem itemLabel="Yabancı" itemValue="YABANCI" />
            <p:ajax event="change" update="#{customerService.musteriTipi}"/>
        </p:selectOneMenu>

        <h:outputLabel value="Ad/Firma Adı: *" for="customerName" />
        <p:inputText id="customerName" value="#{customerService.adFirmaAdi}" title="Müşteri adı." >
            <p:ajax event="change" update="#{customerService.adFirmaAdi}" />
        </p:inputText>

        <h:outputLabel value="Soyad/Ünvan: *" for="customerSurname" />
        <p:inputText id="customerSurname" value="#{customerService.soyadUnvan}" title="Müşteriye ait soyad/ünvan." >
            <p:ajax event="change" update="#{customerService.soyadUnvan}" />
        </p:inputText>

        <h:outputLabel value="TC Kimlik No: *"  />
        <p:inputText id="customerTC" value="#{customerService.tcKimlikNo}" title="TC Kimlik numarasını buraya girin.TC numarası sadece sayılardan oluşmalıdır." >
            <p:ajax event="change" update="#{customerService.tcKimlikNo}" partialSubmit="true" process="@this"/>
        </p:inputText>

        <h:outputLabel value="Vergi No:"  />
        <p:inputText id="customerVergi" value="#{customerService.vergiNo}" title="TC Kimlik numarasını buraya girin.TC numarası sadece sayılardan oluşmalıdır." >
            <p:ajax event="change" update="#{customerService.vergiNo}" partialSubmit="true"/>
        </p:inputText>

        <h:outputLabel value="Müdürlük Kodu: *" />
        <p:inputText id="departmantId" value="#{customerService.mudurlukKodu}" title="Müdürlük kodunu buraya girin.Müdürlük kodu sadece sayılardan oluşmalıdır." >
            <p:ajax event="change" update="#{customerService.mudurlukKodu}" partialSubmit="true"/>
        </p:inputText>

        <h:outputLabel value="Müşteri Kodu: " />
        <p:inputText id="customerId" value="#{customerService.musteriKodu}" title="Müdürlük kodunu buraya girin.Müdürlük kodu sadece sayılardan oluşmalıdır." >
            <p:ajax event="change" update="#{customerService.musteriKodu}" />
        </p:inputText>

        <h:outputLabel value="E-Posta Adresi: " />
        <p:inputText id="customerMail" value="#{customerService.mail}" title="Müşteriye ait e-mail adresini buraya girin." >
            <p:ajax event="change" update="#{customerService.mail}" partialSubmit="true"/>
        </p:inputText>

        <h:outputText value=" "/>
        <p:commandButton id="query" value="Müşteri Sorgula" actionListener="#{customerService.request}" async="true"  onsuccess="panelwv.show()">
            <f:ajax execute="@form" render=":personList" ></f:ajax> 
        </p:commandButton>
    </h:form>

    <h:panelGrid columns="5">
        <h:outputText value=""/>
        <h:outputText value=""/>
        <p:panel widgetVar="panelwv" visible="false" closable="true" header="Sorgu Yapılıyor...">
            <p:graphicImage value="/resources/images/ajaxloadingbar.gif" />  
        </p:panel>
        <h:outputText value=""/>
        <h:outputText value=""/>
    </h:panelGrid>
    <h:outputText value="Bulunan Müşterilere Ait Bilgiler:" />


    <h:form id="personList" rendered="#{not empty customerService.musteriKodu}">
        <p:dataTable value="#{customerService.customer}" var="item" id="persontable" emptyMessage="Henüz müşteri eklemediniz.">
            <p:column headerText="Müşteri/Firma ID">
                #{item.customerId}
            </p:column>
            <p:column headerText="Ad/Firma Adı">
                #{item.customerName}
            </p:column>
            <p:column headerText="Soyad/Ünvan" >
                #{item.customerSurname}
            </p:column>
            <p:column headerText="Müşteri Tipi" >
                #{item.customerType} 
            </p:column> 
            <p:column headerText="Telefon" >
                #{item.customerTel}
            </p:column>
            <p:column headerText="Adres">
                #{item.customerAddress}
            </p:column>
            <p:column headerText="E-Posta">
                #{item.customerMail}
            </p:column>
        </p:dataTable>

    </h:form>
</h:body>

這是我的菜豆:

//some getter and setters
List<Customers> customer = new ArrayList<Customers>();

public List<Customers> getCustomer() {
    return customer;
}

public void setCustomer(List<Customers> customer) {
    this.customer = customer;
}

public String request() {

    final RequestContext context = RequestContext.getCurrentInstance();
    //System.out.println("Progress...");

          //musteriSorgula(musteriSorgulaKriter());
    new Thread(new Runnable() {
        public void run() {
            try {
                musteriKodu = String.valueOf(musteriSorgula(musteriSorgulaKriter()).getMusteriBilgisi().getMusteriKodu());
                List<TelefonBilgisi> tel_result = telefonSorgula(telefonSorgulaKriter(musteriKodu)).getMusteriTelefonListesi();
                //telefon = tel_result.getMusteriTelefonListesi().get(0).getTelefonNo();

                if (tel_result.size() > 0) {
                    for (TelefonBilgisi t : tel_result) {
                        telefon = t.getTelefonNo();
                    }
                } else {
                    telefon = "No telephone.";
                }
                List<UavtAdresBilgisi> uavt_result = uavtAdresSorgula(uavtAdresSorgulaKriter(musteriKodu)).getMusteriUavtAdresListesi();

                if (uavt_result.size() > 0) {
                    for (UavtAdresBilgisi u : uavt_result) {
                        adres = String.valueOf(u.getSehir()) + ", " + String.valueOf(u.getBucak()) + ", " + String.valueOf(u.getKasaba());
                    }
                } else {
                    adres = "No address.";
                }


                Customers cust = new Customers(musteriTipi, BigInteger.valueOf(Long.valueOf(musteriKodu)), adFirmaAdi, soyadUnvan, telefon, adres, mail, projectId);
                if (!customer.contains(cust)) {
                    customer.add(cust);
                    System.out.println("Customer has been added.");

                } else {
                    System.out.println("Customer is still in the list.");
                }
            } catch (Exception ex) {
                Logger.getLogger(CustomerService.class.getName()).log(Level.SEVERE, null, ex);
                context.execute("alert('Try again.')");
            }
        }
    }).start();

    context.execute("panelwv.close()");
    return "";
}

Back bean可以連接到Web服務並獲取信息,我可以在日志中看到它。 一開始我的數據表是空的。 我想要的是將新數據顯示為Web服務響應。 當我將它放在下面時, context.update("personList")不起作用:

customer.add(cust); 

如果有人可以幫助我,我會很高興的。

        <f:ajax execute="@form" render=":personList" ></f:ajax> 

進行更改為

        <f:ajax execute="@form" update="persontable" render=":personList" ></f:ajax> 

好的,所以您要做的是強制客戶端從服務器更新數據表。 看看彗星推技術,以及(如果您不需要支持舊的瀏覽器) WebSocket

如果您四處搜尋,將會發現有關如何使用JSF進行操作的教程。 而且,當您使用Primefaces時,該庫並不支持Comet:檢出p:pushatmosphere支持。

我更喜歡使用@Ömer所說的RemoteCommand組件。

嘗試使用context.execute(“ updater();”);在線程末尾(在大括號內)使用它。

如果使用RichFaces,此問題很容易解決

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM