简体   繁体   English

p:dataTable 未由 PrimeFaces.current().ajax().update 更新

[英]p:dataTable not updated by PrimeFaces.current().ajax().update

I am starting developpment with JSF and PrimeFace datatable.我开始使用 JSF 和 PrimeFace 数据表进行开发。 I have prepared the following xhtml page:我准备了以下 xhtml 页面:

<!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:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui">

        <h:head>
        <title>Find Capital of Countries</title>
        </h:head> 
        <h:body> 
            <h:form id="FrmTest">

                        <p:dataTable id="ListSites"  value="#{testing.SiteSearch()}" var="lst" editable="true">

                        <f:facet name="header">
                            List of Sites
                        </f:facet>

                        <p:column>
                            <f:facet name="header">
                                Site Code
                            </f:facet>
                            #{lst.stCode}
                        </p:column>

                        <p:column headerText="Site Description">
                            <h:outputText value="#{lst.stDescription}" />
                        </p:column>

                        <p:column  headerText="is Active">
                            <div style="text-align: center;">
                                <p:selectBooleanCheckbox value="#{lst.stActive}"  />
                            </div>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                Site Active
                            </f:facet>
                            <div style="text-align: center;">
                                <h:outputText value= "#{lst.stActive}" />
                            </div>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                Modified By
                            </f:facet>
                             #{lst.modifiedBy}
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                Modification Date
                            </f:facet>
                            #{lst.modifiedDate}
                        </p:column>                 

                        <p:column>
                            <f:facet name="header">
                                Has Error
                            </f:facet>
                            #{lst.hasError}
                        </p:column>     

                        <p:column>
                            <f:facet name="header">
                                Error Description
                            </f:facet>
                            #{lst.errorDescription}
                        </p:column>     

                        <p:column>
                            <f:facet name="header">
                                Row State
                            </f:facet>
                            #{lst.rowState}
                        </p:column>     


                    </p:dataTable>



                <h:outputLabel value="Enter Country Name:"/>
                <h:inputText id="country" binding="#{testing.country}"
                valueChangeListener="#{testing.findCapitalListener}"
                immediate="true"
                onchange="document.getElementById('findcapital').click();" />
                <br/>
                <br/>
                <h:outputLabel value="Capital is: " />
                <h:inputText id="capital" binding="#{testing.capital}" immediate="true"/>
                <br/>
                <br/>
                <h:commandButton  value="Submit" partialSubmit="true" />
                <div style="visibility: hidden" >
                    <h:commandButton id="findcapital" value="findcapital" partialSubmit="true"  immediate="true" />
                </div>

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

I want entry made in text box named country to update datatable named ListSites.我希望在名为 country 的文本框中输入以更新名为 ListSites 的数据表。 The associated listener is called (system.out.println made) but the primeface update is not made.关联的侦听器被调用(system.out.println made)但primeface更新没有进行。 Here is the listener:这是听众:

   ```
        public void findCapitalListener(ValueChangeEvent cdl) {
        String country = cdl.getNewValue().toString();
        System.out.println("Country is : " + country);
        StringBuilder capitalCountry = new StringBuilder();
        findCapital(country, capitalCountry);
        capital.setValue(capitalCountry.toString());    
        siteDto = listSiteDto.get(0);
        siteDto.setStDescription(capitalCountry.toString());
        listSiteDto.set(0, siteDto);
        PrimeFaces.current().ajax().update("FrmTest:ListSites");
        //System.out.println("Capital is : " + capital.getValue());
        //System.out.println("New DTO Description : " + siteDto.getStDescription());
        System.out.println("New list Description : " + listSiteDto.get(0).getStDescription());
        }
    ```

The problem was due to the fact that the function populating the datatable (SiteSearch()) was retrieving data from the database.问题是由于填充数据表 (SiteSearch()) 的 function 正在从数据库中检索数据。 At that stage I wanted to refresh the page display before updating the database.在那个阶段,我想在更新数据库之前刷新页面显示。 I replaced the function by the list getter, things are working properly now.我用列表吸气剂替换了 function,现在一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM