【问题标题】:JSF Primefaces Ajax updateJSF Primefaces Ajax 更新
【发布时间】:2013-12-13 15:21:48
【问题描述】:

如何通过 ajax 行选择功能更新我的数据表? 将放在更新参数上的值是什么? 感谢您的帮助

这是我的代码,有一个数据表,当我单击数据表中的某一行后,它会在下面的数据表中显示该行的详细信息,但更新存在问题

<?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:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:p="http://primefaces.org/ui">
    <h:head></h:head>
    <h:body>
        <f:view>
            <h:form id="form">
                <p:dataTable id="users" var="user" value="#{userOS.osList}"
                    paginator="true" rows="10" rowKey="#{user.kisiid}"
                    selection="#{userOS.selectedOS}" selectionMode="single">
                    <f:facet name="header">  
                                            Kullanıcı detaylarını görmek için view butonuna tıklayınız
                                            </f:facet>
                    <p:ajax event="rowSelect" listener="#{userOS.onRowSelect}"
                        update=":form" oncomplete="userDialog" />

                    <p:column headerText="Student No" sortBy="ogrencino"
                        filterBy="ogrencino" id="ogrencino">
                        <h:outputText value="#{user.ogrencino}" />
                        <f:param name="kid" value="#{userOS.osList.rowIndex}" />
                    </p:column>

                    <p:column headerText="Name" sortBy="ad" filterBy="ad" id="ad">
                        <h:outputText value="#{user.ad}" />
                    </p:column>
                    <p:column headerText="Surname" sortBy="soyad" filterBy="soyad"
                        id="soyad">
                        <h:outputText value="#{user.soyad}" />
                    </p:column>
                    <p:column headerText="Faculty" sortBy="altbirim.ad"
                        filterBy="altbirim.ad" id="altbirim">
                        <h:outputText value="#{user.altbirim.ad}" />
                    </p:column>
                    <p:column headerText="Department" sortBy="bolum.ad"
                        filterBy="bolum.ad" id="bolum">
                        <h:outputText value="#{user.bolum.ad}" />
                    </p:column>
                    <p:column headerText="Status" sortBy="ogrencidurum.ad"
                        filterBy="ogrencidurum.ad" id="ogrencidurum">
                        <h:outputText value="#{user.ogrencidurum.ad}" />
                    </p:column>

                    <f:facet name="footer">
                    </f:facet>
                </p:dataTable>


                <p:tabView id="tabView">
                    <p:tab id="dialog" title="User Detail" widgetVar="userDialog">
                        <h:panelGrid id="panelgrid" columns="2" cellpadding="4">
                            <p:dataTable id="display" var="adres" value="#{userOS.adresList}">
                                <p:column headerText="Adres Tipi">
                                    <h:outputText value="#{adres.addressType}" id="adresturu"/>
                                </p:column>
                                <p:column headerText="Adres">
                                    <h:outputText value="#{adres.address}" id="adres"/>
                                </p:column>
                                <p:column headerText="İl">
                                    <h:outputText value="#{adres.city}" id="sehir"/>
                                </p:column>
                                <p:column headerText="Ülke">
                                    <h:outputText value="#{adres.country}" id="ulke"/>
                                </p:column>
                            </p:dataTable>
                        </h:panelGrid>
                    </p:tab>
                    <p:tab id="tab2" title="Godfather Part II">

                    </p:tab>

                    <p:tab id="tab3" title="Godfather Part III">

                    </p:tab>
                </p:tabView>
            </h:form>
        </f:view>
    </h:body>
    </html>

【问题讨论】:

    标签: ajax jsf primefaces


    【解决方案1】:

    您正在更新整个 @form,其中保留了两个 DataTable。
    那么,当您在 First DataTable 中选择一行时,为什么不只更新第二个 DataTable。
    由于您的第二个数据表位于 p:tabView 中,因此它会将 ID 设为 tabView:display
    所以你的p:ajax 将是:

    <p:ajax event="rowSelect" process="@this" listener="#{userOS.onRowSelect}"
                 update=":form:tabView:display" oncomplete="userDialog" />
    

    您可以将第二个表格移动到单独的表格中并更新整个表格。
    根据我使用p:tabView 的经验,我不会在表单中保留p:tabView
    相反,我会将表格保存在 p:tabView 中。
    请参阅此代码:

    <h:form id="form">
       <p:dataTable id="users" var="user" value="#{userOS.osList}" ...>
    
            <p:ajax event="rowSelect" listener="#{userOS.onRowSelect}"
                            update=":tabView:form2" oncomplete="userDialog" />
             .....
             .....
        </p:dataTable>
    </h:form>
    
    <p:tabView id="tabView">
       <p:tab id="dialog" title="User Detail" widgetVar="userDialog">
           <h:panelGrid id="panelgrid" columns="2" cellpadding="4">
    
              <h:form id="form2">
                 <p:dataTable id="display" var="adres" value="#{userOS.adresList}">
                     ......
                     ......
                  </p:dataTable>
               </h:form>
    
           </h:panelGrid>
        </p:tab>
    </p:tabView>
    

    【讨论】:

    • 添加 tabView:display Ara 16, 2013 10:55:17 AM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException SEVERE: Error Rendering View[/layout. xhtml] javax.faces.FacesException:找不到从“form:users”引用的表达式“tabView:display”的组件。
    • 我做了你写的单独表格但没有任何运气它只更新了一次,我的代码中是否遗漏了什么?
    • 否问题仅出在 TabView 上。最后我可以说,尝试更新整个 Tab View 一次
    猜你喜欢
    • 2014-06-11
    • 2011-12-17
    • 2011-05-27
    • 2013-05-11
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多