簡體   English   中英

從中查看選定行的數據 <p:dataTable> 通過 <p:dialog>

[英]Viewing data of selected row from <p:dataTable> through <p:dialog>

我在使用Dialog從DataTable中顯示所選行的數據時遇到問題。

在此處輸入圖片說明 我選擇的每一行都會在對話框中顯示第一行(父行)的數據

在此處輸入圖片說明

刪除其他行可以正常工作。 我已經為此工作了幾天,但仍然無法解決這一問題。

這是我在DataTable中的代碼

<h:form id="tableForm">

        <!-- Account Data Table --> 


        <p:dataTable id="table" var="account" value="#{accountController.accounts}" widgetVar="accountTable" rowKey="#{account.id}" paginator="true" rows="15"
                     paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" selection="#{accountController.account}"
                     paginatorPosition="bottom" lazy="true">  


            <p:column selectionMode="single" style="width:18px" />

            <p:column headerText="Lastname" sortBy="#{account.marketingPerson.lastName}">  
                <h:outputText value="#{account.marketingPerson.lastName}" />  
            </p:column>  

            <p:column headerText="Firstname" sortBy="#{account.marketingPerson.firstName}">  
                <h:outputText value="#{account.marketingPerson.firstName}" />  
            </p:column> 

            <p:column headerText="Middlename" sortBy="#{account.marketingPerson.middleName}">  
                <h:outputText value="#{account.marketingPerson.middleName}" />  
            </p:column> 

            <p:column headerText="Position">  
                <h:outputText value="#{account.marketingPerson.position}" />  
            </p:column>   

            <f:facet name="footer">

                <!-- View Button -->
                <p:commandButton value="View" oncomplete="view.show()" icon="view-icon" >

                    <f:setPropertyActionListener target="#{accountController.account}" value="#{account}"/>

                </p:commandButton>

                <!-- Edit Button -->
                <p:commandButton  value="Edit" onclick="view.show()" icon="edit-icon">

                </p:commandButton>

                <!-- Delete Button -->
                <p:commandButton value="Delete" onclick="cd.show()" icon="delete-icon" >
                    <f:setPropertyActionListener target="#{accountController.account}" value="#{account}" />
                </p:commandButton>
            </f:facet>     

        </p:dataTable> 

        <!-- Confirmation -->
        <p:confirmDialog 
            header="Delete Action Confirmation" severity="alert"
            widgetVar="cd">

            <f:facet name="message">
                <h:outputText value="Are you sure?" />
            </f:facet>

            <p:commandButton value="Yes" actionListener="#{accountController.delete}" update="table"
                             oncomplete="cd.hide()">
                <f:ajax render="table" />
            </p:commandButton>

            <p:commandButton value="No" onclick="cd.hide()" type="button" />
        </p:confirmDialog>
    </h:form>

查看帳戶對話框

<p:dialog header="View Account" widgetVar="view" resizable="false" id="viewDlg" draggable="false" >         
        <h:form id="viewForm">
            <p:panelGrid id="display" columns="2" style="margin:0 auto;">

                <f:facet name="header">
                    <p> <h:graphicImage value="resources/images/icons-button/search_business_user.png" />
                        #{account.marketingPerson.lastName}, #{account.marketingPerson.firstName} #{account.marketingPerson.middleName}
                    </p>
                </f:facet>

                <p:outputLabel value="ID Number:" />
                <p:outputLabel value="#{account.marketingPerson.idNumber}" />

                <p:outputLabel value="Birth Date:" />
                <p:outputLabel value="#{account.marketingPerson.birthDate}" />

                <p:outputLabel value="Telephone Number:" />
                <p:outputLabel value="#{account.marketingPerson.telNumber}" />

                <p:outputLabel value="Mobile Number:" />
                <p:outputLabel value="#{account.marketingPerson.mobileNumber}" />

                <p:outputLabel value="Email Address:" />
                <p:outputLabel value="#{account.marketingPerson.emailAddress}" />

                <f:facet name="footer">
                    <p:commandButton type="button" value="Edit" />
                </f:facet>
            </p:panelGrid>
        </h:form>
    </p:dialog>

每次從表中選擇數據時,在DataTable上使用p:ajax來更新ManagedBean的值。
並使用update屬性來使用新選擇的值重新渲染p:dialog p:panelGrid

<p:ajax event="rowSelect" update=":viewForm:display" /> 

使用Faces Converter解決了這一問題

暫無
暫無

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

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