私はprimefaces3.3バージョンを使用しています。データテーブルのフッターの一部として詳細と CRUD ボタンを表示するデータテーブルがあります。データテーブル内の特定の行を選択した後、CRUD ボタンをクリックすると、ダイアログが表示されます。
ダイアログの [保存] ボタンをクリックすると、データが保存され、データテーブルが更新されます。ただし、この後、 sortBy 、ページネーション オプションは機能しません。これに伴い、データテーブルの選択モードが複数に変更されます。この動作は IE 8 と FF 12 で再現可能です。Google Chrome 19 では問題なく動作します。xhtml と Backing Bean コードの両方が添付されています。
account.xhtml
<h:head>
<script type="text/javascript">
function handleDialogSubmit(xhr, status, args) {
if (args != null) {
if (args.validationFailed) {
accountDialog.show();
return true;
} else {
accountDialog.hide();
return true;
}
}
}
</script>
</h:head>
<h:body>
<ui:composition template="/template.xhtml">
<ui:define name="body">
<h:form id="form" prependId="false">
<p:contextMenu for="dataTable">
<p:menuitem value="View" update=":form2:accountDisplay"
icon="ui-icon-search" oncomplete="accountDialog.show()"
process="@this">
<f:setPropertyActionListener value="#{account}"
target="#{accountBean.selectedAccount}" />
</p:menuitem>
<p:menuitem value="Edit" update=":form2:accountDisplay"
icon="ui-icon-edit" oncomplete="accountDialog.show()"
process="@this" immedeate="true">
<f:setPropertyActionListener value="#{account}"
target="#{accountBean.currentAccount}" />
</p:menuitem>
<p:menuitem value="Delete" update=":dialogForm:confirmDialog"
icon="ui-icon-close" oncomplete="confirmation.show()" />
</p:contextMenu>
<h:panelGroup id="dataPanel">
<p:dataTable var="account" value="#{accountBean.accounts}"
paginator="true" rows="20" rowKey="#{account.accountCode}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
id="dataTable">
<p:column
headerText="Edit|View|Delete">
<p:commandLink id="selectButton1" update=":form2:accountDisplay"
title="Edit" process="@this" oncomplete="accountDialog.show()">
<h:outputText value="Edit" />
<f:setPropertyActionListener value="#{account}"
target="#{accountBean.currentAccount}" />
</p:commandLink>
|
<p:commandLink id="detailButton1"
update=":form2:accountDisplay" title="View Details"
oncomplete="accountDialog.show()" process="@this">
<h:outputText value="View" />
<f:setPropertyActionListener value="#{account}"
target="#{accountBean.selectedAccount}" />
</p:commandLink>
|
<p:commandLink id="showDialogButton1"
update=":dialogForm:confirmDialog" title="Delete"
oncomplete="confirmation.show()" process="@this">
<h:outputText value="Delete" />
<f:setPropertyActionListener value="#{account}"
target="#{accountBean.selectedAccount}" />
</p:commandLink>
</p:column>
<p:column id="accountCode" headerText=" Account Code"
sortBy="#{account.accountCode}" filterBy="#{account.accountCode}"
filterMatchMode="startsWith" footerText="startsWith">
<h:outputText value="#{account.accountCode}" />
</p:column>
<p:column id="alertCode" headerText=" Alert Code"
sortBy="#{account.alertCode}" filterBy="#{account.alertCode}"
filterMatchMode="contains" footerText="contains">
<h:outputText value="#{account.alertCode}" />
</p:column>
<p:column id="clearAgentID" headerText=" Clr Agent#"
sortBy="#{account.clearAgentID}"
filterBy="#{account.clearAgentID}" filterMatchMode="startsWith"
footerText="startsWith">
<h:outputText value="#{account.clearAgentID}" />
</p:column>
<p:column id="globalAccountNum" headerText=" Global Acct#"
sortBy="#{account.globalAccountNum}"
filterBy="#{account.globalAccountNum}"
filterMatchMode="startsWith" footerText="startsWith">
<h:outputText value="#{account.globalAccountNum}" />
</p:column>
<p:column id="safeKeepingAccountNum"
headerText=" Safekeeping Acct#"
sortBy="#{account.safeKeepingAccountNum}"
filterBy="#{account.safeKeepingAccountNum}"
filterMatchMode="startsWith" footerText="startsWith">
<h:outputText value="#{account.safeKeepingAccountNum}" />
</p:column>
<p:column id="destinationID" headerText=" Primary Dest ID"
sortBy="#{account.destinationID}"
filterBy="#{account.destinationID}" filterMatchMode="startsWith"
footerText="startsWith">
<h:outputText value="#{account.destinationID}" />
</p:column>
<p:column id="addlDestinationID1" headerText=" Addl Dest ID1"
sortBy="#{account.addlDestinationID1}"
filterBy="#{account.addlDestinationID1}"
filterMatchMode="startsWith" footerText="startsWith">
<h:outputText value="#{account.addlDestinationID1}" />
</p:column>
<p:column id="addlDestinationID2" headerText=" Addl Dest ID2"
sortBy="#{account.addlDestinationID2}"
filterBy="#{account.addlDestinationID2}"
filterMatchMode="startsWith" footerText="startsWith">
<h:outputText value="#{account.addlDestinationID2}" />
</p:column>
<p:column id="addlDestinationID3" headerText=" Addl Dest ID3"
sortBy="#{account.addlDestinationID3}"
filterBy="#{account.addlDestinationID3}"
filterMatchMode="startsWith" footerText="startsWith">
<h:outputText value="#{account.addlDestinationID3}" />
</p:column>
<p:column id="destinationName" headerText=" Primary Dest Name"
sortBy="#{account.destinationName}"
filterBy="#{account.destinationName}"
filterMatchMode="startsWith" footerText="startsWith">
<h:outputText value="#{account.destinationName}" />
</p:column>
<p:column id="conBIC" headerText=" Cont BIC"
sortBy="#{account.conBIC}" filterBy="#{account.conBIC}"
filterMatchMode="startsWith" footerText="startsWith">
<h:outputText value="#{account.conBIC}" />
</p:column>
<p:column id="accountStatus" headerText=" Status"
sortBy="#{account.accountStatus}"
filterOptions="#{account.accountStatus}" filterMatchMode="exact"
footerText="exact">
<h:outputText value="#{account.accountStatus}" />
</p:column>
<p:column id="comments"
headerText="Comments"
sortBy="#{account.comments}" filterBy="#{account.comments}"
filterMatchMode="startsWith" footerText="startsWith">
<h:outputText value="#{account.comments}" />
</p:column>
<p:column id="createdBy" headerText=" Created By"
sortBy="#{account.createdBy}" filterBy="#{account.createdBy}"
filterMatchMode="startsWith" footerText="startsWith">
<h:outputText value="#{account.createdBy}" />
</p:column>
<p:column id="createdDate" headerText=" Created Date"
sortBy="#{account.createdDate}" filterBy="#{account.createdDate}"
filterMatchMode="startsWith" footerText="startsWith">
<h:outputText value="#{account.createdDate}" />
</p:column>
<p:column id="modifiedBy" headerText=" Modified By"
sortBy="#{account.modifiedBy}" filterBy="#{account.modifiedBy}"
filterMatchMode="startsWith" footerText="startsWith">
<h:outputText value="#{account.modifiedBy}" />
</p:column>
<p:column id="modifiedDate" headerText=" Modified Date"
sortBy="#{account.modifiedDate}"
filterBy="#{account.modifiedDate}" filterMatchMode="startsWith"
footerText="startsWith">
<h:outputText value="#{account.modifiedDate}" />
</p:column>
<!-- <f:facet name="footer">
<p:toolbar>
<p:toolbarGroup align="left">
<p:tooltip for="btnAdd" value="Add New Account" />
<p:commandButton id="btnRefresh" styleClass="refreshButton"
title="Refresh Account Information" value="Refresh"
icon="ui-icon-refresh"
actionListener="#{accountBean.populateAccounts}"
update=":form:dataTable,:form2:display" immediate="true"/>
<p:tooltip for="btnRefresh" value="Refresh Account Details" />
<p:commandButton id="selectButton" update=":form2:accountDisplay"
icon="ui-icon-edit" title="Edit Account Details" value="Edit"
process="@this" oncomplete="accountDialog.show()" immediate="true">
<f:setPropertyActionListener value="#{account}"
target="#{accountBean.currentAccount}" />
</p:commandButton>
<p:commandButton id="detailButton" value="View"
icon="ui-icon-view" update=":form2:accountDisplay"
title="View Account Details" oncomplete="detailDialog.show()"
process="@this" immediate="true">
<f:setPropertyActionListener value="#{account}"
target="#{accountBean.selectedAccount}" />
</p:commandButton>
<p:commandButton id="showDialogButton" icon="ui-icon-delete"
value="Delete" update=":dialogForm:confirmDialog"
title="Delete Account Details" oncomplete="confirmation.show()"
process="@this" immediate="true">
<f:setPropertyActionListener value="#{account}"
target="#{accountBean.selectedAccount}" />
</p:commandButton>
</p:toolbarGroup>
</p:toolbar>
</f:facet> -->
<f:facet name="footer">
<p:toolbar>
<p:toolbarGroup align="left">
<p:commandButton id="btnAdd" value="Add" title="Add New Account"
icon="ui-icon-add"
oncomplete="accountDialog.show()" />
<p:commandButton id="editButton" value="Edit" icon="ui-icon-edit"
update=":form2:accountDisplay" oncomplete="accountDialog.show()">
</p:commandButton>
<p:commandButton id="showDialogButton" icon="ui-icon-delete"
value="Delete"
title="Delete Account Details" oncomplete="confirmation.show()">
</p:commandButton>
<p:commandButton id="viewButton" value="View"
icon="ui-icon-search" update=":form2:display"
oncomplete="accountDialog.show()" />
<p:commandButton id="btnRefresh" styleClass="refreshButton"
title="Refresh Account Information" value="Refresh"
icon="ui-icon-refresh"
actionListener="#{accountBean.populateAccounts}"
update=":form:dataTable"/>
</p:toolbarGroup>
</p:toolbar>
</f:facet>
</p:dataTable>
</h:panelGroup>
</h:form>
<h:form id="form2" >
<!-- <p:growl id="growl" showDetail="true" sticky="true" /> -->
<p:dialog id="basicDialog" header="Account Details"
widgetVar="detailDialog" resizable="false">
<h:panelGrid id="display" columns="2">
<h:outputText value="#{bundle.AccountLabel_accountCode}" />
<h:outputText value="#{accountBean.selectedAccount.accountCode}"
title="#{bundle.AccountTitle_accountCode}" />
<h:outputText value="#{bundle.AccountLabel_alertCode}" />
<h:outputText value="#{accountBean.selectedAccount.alertCode}"
title="#{bundle.AccountTitle_alertCode}" />
<h:outputText value="#{bundle.AccountLabel_clearAgentID}" />
<h:outputText value="#{accountBean.selectedAccount.clearAgentID}"
title="#{bundle.AccountTitle_clearAgentID}" />
<h:outputText value="#{bundle.AccountLabel_globalAccountNum}" />
<h:outputText
value="#{accountBean.selectedAccount.globalAccountNum}"
title="#{bundle.AccountTitle_globalAccountNum}" />
<h:outputText value="#{bundle.AccountLabel_safeKeepingAccountNum}" />
<h:outputText
value="#{accountBean.selectedAccount.safeKeepingAccountNum}"
title="#{bundle.AccountTitle_safeKeepingAccountNum}" />
<h:outputText value="#{bundle.AccountLabel_destinationID}" />
<h:outputText value="#{accountBean.selectedAccount.destinationID}"
title="#{bundle.AccountTitle_destinationID}" />
<h:outputText value="#{bundle.AccountLabel_addlDestinationID1}" />
<h:outputText
value="#{accountBean.selectedAccount.addlDestinationID1}"
title="#{bundle.AccountTitle_addlDestinationID1}" />
<h:outputText value="#{bundle.AccountLabel_addlDestinationID2}" />
<h:outputText
value="#{accountBean.selectedAccount.addlDestinationID2}"
title="#{bundle.AccountTitle_addlDestinationID2}" />
<h:outputText value="#{bundle.AccountLabel_addlDestinationID3}" />
<h:outputText
value="#{accountBean.selectedAccount.addlDestinationID3}"
title="#{bundle.AccountTitle_addlDestinationID3}" />
<h:outputText value="#{bundle.AccountLabel_destinationName}" />
<h:outputText
value="#{accountBean.selectedAccount.destinationName}"
title="#{bundle.AccountTitle_destinationName}" />
<h:outputText value="#{bundle.AccountLabel_conBIC}" />
<h:outputText value="#{accountBean.selectedAccount.conBIC}"
title="#{bundle.AccountTitle_conBIC}" />
<h:outputText value="#{bundle.AccountLabel_accountStatus}" />
<h:outputText value="#{accountBean.selectedAccount.accountStatus}"
title="#{bundle.AccountTitle_accountStatus}" />
<h:outputText value="#{bundle.AccountLabel_comments}" />
<h:outputText value="#{accountBean.selectedAccount.comments}"
title="#{bundle.AccountTitle_comments}" />
<h:outputText value="#{bundle.AccountLabel_createdBy}" />
<h:outputText value="#{accountBean.selectedAccount.createdBy}"
title="#{bundle.AccountTitle_createdBy}" />
<h:outputText value="#{bundle.AccountLabel_createdDate}" />
<h:outputText value="#{accountBean.selectedAccount.createdDate}"
title="#{bundle.AccountTitle_createdDate}" />
<h:outputText value="#{bundle.AccountLabel_modifiedBy}" />
<h:outputText value="#{accountBean.selectedAccount.modifiedBy}"
title="#{bundle.AccountTitle_modifiedBy}" />
<h:outputText value="#{bundle.AccountLabel_modifiedDate}" />
<h:outputText value="#{accountBean.selectedAccount.modifiedDate}"
title="#{bundle.AccountTitle_modifiedDate}" />
</h:panelGrid>
</p:dialog>
<p:dialog header="Account Detail" widgetVar="accountDialog"
resizable="false" height="600" width="600" showEffect="clip"
hideEffect="fold" id="accountDialog" >
<p:messages id="messages" autoUpdate="true" />
<h:panelGrid id="accountDisplay" columns="2" cellpadding="4">
<h:outputLabel value="Account Code:" for="accountCode" />
<p:inputText label="Account Code" id="accountCode"
value="#{accountBean.currentAccount.accountCode}"
title="Account Code" required="true"
validatorMessage="#{bundle.AccountValidationAccountCode}" requiredMessage="#{bundle.AccountRequiredMessage_accountCode}">
</p:inputText>
<h:outputLabel value="Alert Code:" for="alertCode" />
<p:inputText label="Alert Code" id="alertCode"
value="#{accountBean.currentAccount.alertCode}"
title="Alert Code" required="true"
validatorMessage="#{bundle.AccountValidationAlertCode}" requiredMessage="#{bundle.AccountRequiredMessage_alertCode}">
</p:inputText>
<h:outputLabel value="Clr Agent#:" for="clearAgentID" />
<p:inputText label="Clr Agent#" id="clrAgent"
value="#{accountBean.currentAccount.clearAgentID}"
title="Clr Agent#" required="true"
requiredMessage="#{bundle.AccountRequiredMessage_clearAgentID}">
</p:inputText>
<h:outputLabel value="Global Acct#:" for="globalAccountNum" />
<p:inputText label="Global Acct#" id="globalAccountNum"
value="#{accountBean.currentAccount.globalAccountNum}"
title="Global Acct#" required="true"
requiredMessage="#{bundle.AccountRequiredMessage_globalAccountNum}">
</p:inputText>
<h:outputLabel value="SafeKeeping Acct#:"
for="safeKeepingAccountNum" />
<p:inputText label="Safekeeping Account Number"
id="safeKeepingAccountNum"
value="#{accountBean.currentAccount.safeKeepingAccountNum}"
title="Safekeeping Account Number" required="true"
validatorMessage="#{bundle.AccountValidationSafeKeepingAccountNum}" requiredMessage="#{bundle.AccountRequiredMessage_safeKeepingAccountNum}">
</p:inputText>
<h:outputLabel value="Primary Dest ID:" for="destinationID" />
<p:inputText label="Primary Dest ID" id="destinationID"
value="#{accountBean.currentAccount.destinationID}"
title="Primary Dest ID" required="true"
requiredMessage="#{bundle.AccountRequiredMessage_destinationID}">
</p:inputText>
<h:outputLabel value="Addl Dest ID1:" for="addlDestinationID1" />
<p:inputText label="Addl Dest ID1" id="addlDestinationID1"
value="#{accountBean.currentAccount.addlDestinationID1}"
title="Addl Dest ID1" required="true"
requiredMessage="#{bundle.AccountRequiredMessage_addlDestinationID1}">
</p:inputText>
<h:outputLabel value="Addl Dest ID2:" for="addlDestinationID2" />
<p:inputText label="Addl Dest ID2" id="addlDestinationID2"
value="#{accountBean.currentAccount.addlDestinationID2}"
title="Addl Dest ID2" required="true"
requiredMessage="#{bundle.AccountRequiredMessage_addlDestinationID2}">
</p:inputText>
<h:outputLabel value="Addl Dest ID3:" for="addlDestinationID3" />
<p:inputText label="Addl Dest ID3" id="addlDestinationID3"
value="#{accountBean.currentAccount.addlDestinationID3}"
title="Addl Dest ID3" required="true"
requiredMessage="#{bundle.AccountRequiredMessage_addlDestinationID3}">
</p:inputText>
<h:outputLabel value="Primary Dest Name:" for="destinationName" />
<p:inputText label="Primary Dest Name" id="destinationName"
value="#{accountBean.currentAccount.destinationName}"
title="Primary Dest Name" required="true"
requiredMessage="#{bundle.AccountRequiredMessage_destinationName}">
</p:inputText>
<h:outputLabel value="Cont BIC:" for="conBIC" />
<p:inputText label="Cont BIC" id="conBICText"
value="#{accountBean.currentAccount.conBIC}" title="Cont BIC"
required="true"
requiredMessage="#{bundle.AccountRequiredMessage_conBIC}">
</p:inputText>
<h:outputLabel value="Status:" for="accountStatus" />
<p:inputText label="Status" id="conBIC"
value="#{accountBean.currentAccount.accountStatus}"
title="Status" required="true"
requiredMessage="#{bundle.AccountRequiredMessage_accountStatus}">
</p:inputText>
<h:outputLabel value="Comments:" for="comments" />
<p:inputTextarea id="comments" rows="5" cols="30" maxlength="10" value="#{accountBean.currentAccount.comments}"
autoResize="false" required="true" requiredMessage="#{bundle.AccountRequiredMessage_comments}"/>
<h:outputLabel />
<h:outputLabel />
<!-- <p:separator id="customSeparator" style="width:500px;height:1px" /> -->
<f:facet name="footer">
<!-- <p:commandButton value="New" icon="ui-icon-check"/> -->
<h:outputLabel />
<p:commandButton id="save" styleClass="saveButton" value="Save"
icon="ui-icon-check"
actionListener="#{accountBean.createOrUpdate}"
oncomplete="handleDialogSubmit(xhr,status,args);"/>
<!-- update=":form:dataTable,:form2:display" onsuccess="accountDialog.hide()" ajax="false"/> -->
<p:commandButton id="cancel" actionListener="#{accountBean.cancel}" styleClass="cancelButton" value="Cancel"
icon="ui-icon-cancel" oncomplete="accountDialog.hide()" process="@this"/>
<p:commandButton id="btnRefresh" styleClass="refreshButton1"
title="Refresh Account Information" value="Refresh"
icon="ui-icon-refresh"
actionListener="#{accountBean.populateAccounts}"
update=":form:dataTable"/>
</f:facet>
</h:panelGrid>
</p:dialog>
</h:form>
<h:form id="dialogForm">
<p:confirmDialog id="confirmDialog" header="Confirm Delete Account"
severity="alert" widgetVar="confirmation">
<f:facet name="message">
<h:outputText
value="Delete #{accountBean.selectedAccount.accountCode}?" />
</f:facet>
<p:commandButton id="confirm" value="Yes"
oncomplete="confirmation.hide()" update=":form:dataTable"
actionListener="#{accountBean.remove}" ajax="false"/>
<p:commandButton id="decline" value="No"
onclick="confirmation.hide()" type="button" ajax="false"/>
</p:confirmDialog>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
AccountBean.java
package com.cba.web.beans;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.primefaces.context.RequestContext;
import com.cba.services.AccountService;
import com.cba.utils.JsfUtils;
import com.cba.utils.ServiceLocator;
import com.cba.web.model.Account;
@ManagedBean(name = "accountBean")
@ViewScoped
public class AccountBean implements Serializable {
private transient AccountService accountService;
private List<Account> accounts;
private Account selectedAccount = new Account();
private Account currentAccount = new Account();
public Account getSelectedAccount() {
return selectedAccount;
}
public void setSelectedAccount(Account selectedAccount) {
this.selectedAccount = selectedAccount;
}
public Account getCurrentAccount() {
return currentAccount;
}
public void setCurrentAccount(Account currentAccount) {
this.currentAccount = currentAccount;
}
public AccountBean() {
populateAccounts();
}
public AccountService getAccountService() {
return accountService;
}
public void setAccountService(AccountService accountService) {
this.accountService = accountService;
}
public List<Account> getAccounts() {
return accounts;
}
public void populateAccounts() {
accountService = (AccountService) ServiceLocator.getInstance().getBean(
"accountService");
accounts = accountService.getAccountDetails();
}
public void createOrUpdate(ActionEvent e) {
try {
System.out.println("entering createOrUpdate in AccountBean");
accountService = (AccountService) ServiceLocator.getInstance()
.getBean("accountService");
accountService.updateAccountDetails(currentAccount);
currentAccount = new Account();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void cancel(ActionEvent e) {
clear();
}
public void remove(ActionEvent e) {
try {
accountService = (AccountService) ServiceLocator.getInstance()
.getBean("accountService");
accountService.deleteAccountDetails(selectedAccount);
selectedAccount = new Account();
populateAccounts();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void clear() {
currentAccount = new Account();
UIViewRoot viewRoot =
FacesContext.getCurrentInstance().getViewRoot();
UIComponent component1 = viewRoot.findComponent("form2");
JsfUtils.clearComponentHierarchy(component1);
}
}
これに関する情報は非常に役立ちます。