我遇到此问题时,使用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>
答案 0 :(得分:1)
每次从Table中选择数据时,在DataTable上使用p:ajax
更新ManagedBean上的值。
并使用update
属性将p:panelGrid
中的p:dialog
重新呈现为新的选定值。
<p:ajax event="rowSelect" update=":viewForm:display" />
答案 1 :(得分:0)
使用Faces Converter
解决了这个问题