简体   繁体   English

Primefaces数据表排序和过滤直到rowSelect才能工作

[英]Primefaces datatable sorting and filtering not working until rowSelect

I know that this question may be duplicated but i really can't find the solution for my issue; 我知道这个问题可能重复,但我真的找不到解决问题的方法; my Issue that datatable functionality like sorting and filtering not working unless i click on any row to show the details dialog after i close the dialog everything "sorting, filtering" is working normally and as expected. 我的问题,排序和过滤等数据库功能无法正常工作,除非我在关闭对话框后单击任何行显示详细信息对话框,所有“排序,过滤”正常工作并按预期工作。

here is my code : Bean.java 这是我的代码: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");
    }
}

And Here is the xhtml 这是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>

I have seen a similar issue on my screen some time back. 一段时间以后,我在屏幕上看到了类似的问题。 When the page is not completely rendered, sort and filtering wont happen. 当页面未完全呈现时,排序和过滤不会发生。 For testing purposes, could you try removing the java scripts and try. 出于测试目的,您可以尝试删除java脚本并尝试。 Another way to debug is using chrome hit f12 and look at the networks tab for finding out the ajax calls. 另一种调试方法是使用chrome hit f12并查看网络选项卡以查找ajax调用。 Hope this helps. 希望这可以帮助。

I had the same issue, in my case I wasn't just setting the selected object in my "setSelected", I was also doing some operation on the selected object. 我有同样的问题,在我的情况下,我不只是在我的“setSelected”中设置所选对象,我也在对所选对象进行一些操作。 The problem is: "setSelected" is called before any row is selected, with setSelected(null). 问题是:在选择任何行之前调用“setSelected”,使用setSelected(null)。 If you do any operation with this "null" value you can have serious problems. 如果使用此“null”值执行任何操作,则可能会出现严重问题。 The solution is just to check for null before doing the needed operations. 解决方案是在执行所需操作之前检查null。

I don't know if your problem is the same, but since you didn't post your code for "setSelected", it could be it. 我不知道你的问题是否相同,但由于你没有发布“setSelected”的代码,可能就是这样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM