我知道这个问题可能会重复,但我真的找不到我的问题的解决方案;我的问题是排序和过滤等数据表功能不起作用,除非我在关闭对话框后单击任何行以显示详细信息对话框,所有“排序、过滤”都按预期正常工作。
这是我的代码:Bean.java
@ViewScoped
public class HomeBean implements Serializable {
private List<Ticket> filteredTickets;
private List<Ticket> tickets;
private Ticket selectedTicket;
private Ticket[] selectedTickets;
public HomeBean() {
super();
}
@PostConstruct
public void init() {
getData();
}
private void getData() {
TicketFacade service;
service = TicketFacade.getInstance();
try {
tickets = service.selectTickets();
} catch (Exception e) {
logger.error(Utilities.printStackTrace(e));
}
}
// setter & getters
@PreDestroy
public void finalize() {
logger.debug("@PreDestroy");
}
}
这是xhtml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<f:view contentType="text/html">
<h:head>
<f:facet name="first">
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type" />
<title>Home Page</title>
</f:facet>
<script type="text/javascript">
window.history.forward();
function noBack() {
window.history.forward();
}
</script>
</h:head>
<h:body id="body-view" onload="noBack();"
onpageshow="if (event.persisted) noBack();" onunload="">
<f:view locale="#{userManager.locale}">
<h:form id="Ticket">
<p:dataTable var="ticket" value="#{homeBean.tickets}"
rowKey="#{ticket.id}" paginator="true" rows="15"
selection="#{homeBean.selectedTicket}" selectionMode="single"
filteredValue="#{homeBean.filteredTickets}" id="ticketsTable"
emptyMessage="#{lbl.noTicketsFound}"
style="margin-bottom:10px;margin-top:10px;">
<p:ajax event="rowSelect" update=":Ticket:display"
oncomplete="ticketDialog.show()" />
<f:facet name="header">#{lbl.listOfTickets}</f:facet>
<p:column headerText="#{lbl.tblId}" sortBy="#{ticket.id}"
filterBy="#{ticket.id}" id="id">
<h:outputLink value="#{edit.xhtml?id=#{ticket.id}">#{ticket.id}</h:outputLink>
</p:column>
<p:column headerText="#{lbl.tblTitle}" sortBy="#{ticket.title}"
filterBy="#{ticket.title}" id="title"> #{ticket.title}
</p:column>
</p:dataTable>
<p:dialog header="#{lbl.moreTicketDetails}" widgetVar="ticketDialog"
resizable="true" width="500" showEffect="explode"
hideEffect="explode" closable="true" draggable="true">
<h:panelGrid id="display" columns="2" cellpadding="4"
dir="#{lbl.dir}">
<h:outputText for="shortDescription"
value="#{lbl.shortDescription}" />
<h:outputText id="shortDescription"
value="#{homeBean.selectedTicket.shortDescription}" />
<h:outputText for="callCenterList" value="#{lbl.callcenters}" />
<h:outputText id="callCenterList"
value="#{homeBean.selectedCallCenters}">
</h:outputText>
</h:panelGrid>
</p:dialog>
</h:form>
</f:view>
</h:body>
</f:view>
</html>