1

我有一个表单,用户应该输入一些值以从 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); 

如果有人可以帮助我,我将不胜感激。

4

4 回答 4

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

更改为

        <f:ajax execute="@form" update="persontable" render=":personList" ></f:ajax> 
于 2013-05-06T13:57:26.203 回答
0

如果使用 RichFaces,这个问题很容易解决

于 2013-05-06T14:15:45.583 回答
0

好的,所以您要做的是强制客户端从您的服务器更新数据表。看看cometpush 技术,以及(如果您不需要支持旧版浏览器)WebSocket

如果您在周围搜索,您会找到有关如何使用 JSF 进行操作的教程。当您使用 Primefaces 时,并不是说这个库支持彗星:结账p:pushatmosphere支持。

于 2013-05-06T10:45:06.507 回答
0

正如@Ömer 所说,我更喜欢使用 RemoteCommand 组件。

尝试使用 context.execute("updater();"); 在线程末尾(线程大括号内)使用它

于 2013-05-06T14:08:06.177 回答