1

我在使用 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>
4

2 回答 2

1

p:ajax每次从 Table 中选择数据时,使用DataTable 更新 ManagedBean 上的值。
并使用update属性来重新渲染新p:panelGridp:dialog选定值。

<p:ajax event="rowSelect" update=":viewForm:display" /> 
于 2013-09-22T08:21:36.123 回答
0

使用 Faces Converter 解决了这个问题

于 2013-09-25T16:04:26.663 回答