p:datascroller只懒得加载一次。

问题描述 投票:0回答:1

我们从primefaces中实现了datascroller,并扩展了lazy=true,这在第一次懒惰加载时运行良好。但是当我向下滚动时,前台没有触发任何事件。后台则按预期工作。

我通过改变块的大小进行测试,以更好地了解后端代码中发生了什么。我们重写了当你到达页面末端时,primefaces调用的加载函数。我修改了代码,使其不能通过滚动来懒加载,因此我实现了一个按钮,当你点击该按钮时,就会加载下一个块。但点击一次按钮后,按钮就消失了。

Xhtml。

                        <p:dataScroller value="#{stakeholderOverviewController.model}" var="stakeholder" chunkSize="50" lazy="true" rowIndexVar="test">

                            <f:facet name="header">
                                Scroll Down to Load More Cars 
                            </f:facet>
                            <f:facet name="loader">
                                <p:commandButton type="button" value="More" icon="pi pi-chevron-circle-down"/>
                            </f:facet>
                            <h:panelGrid columns="2" style="width:100%" columnClasses="logo,detail">
                                <p:outputPanel>
                                    <h:panelGrid columns="2" cellpadding="5">
                                        <h:outputText value="Id:" />
                                        <h:outputText value="#{stakeholder.lastname}" style="font-weight: bold"/>

                                        <h:outputText value="Year:" />
                                        <h:outputText value="#{stakeholder.firstname}" style="font-weight: bold"/>

                                    </h:panelGrid>
                                </p:outputPanel>
                            </h:panelGrid>
                            <ui:include  rendered="#{empty stakeholder}" src="/WEB-INF/compositions/stakeholderEmptyModel.xhtml" />
                        </p:dataScroller>

这是Controller的后台代码。

    public StakeholderOverviewController() {
        model = new LazyDataModel<StakeholderSearchWrapper>() {

            @Override
            public List<StakeholderSearchWrapper> load(int first, int pageSize, String sortField, SortOrder sortOrder,
                    Map filters) {

                List<StakeholderSearchWrapper> execQuery = execQuery(first, pageSize);
                return execQuery;
            }
        };
        model.setRowCount(0);
    }

....

protected synchronized List<StakeholderSearchWrapper> execQuery(int first, int pageSize) {
        if (tmpfirst != first || tmppageSize != pageSize || reExecQuery) {
            reExecQuery = false;
            tmpfirst = first;
            tmppageSize = pageSize;

            tmpModel = new LinkedList<>();

            // Query for stakeholder
            queryresponse = stakeholderService.findByLastnameOrFirstmanOwnerOrShare(getSearchText(), getClientId(),
                    first, pageSize, selectedFacets, nameSort[getSort()]);

            setFacets(queryresponse.getFacetFields());
            Set<String> stakeholderIds = new HashSet<String>();

            // convert for view
            for (SolrDocument details : queryresponse.getResults()) {
                StakeholderSearchWrapper stakeholderSearchWrapper = new StakeholderSearchWrapper(details);

                tmpModel.add(stakeholderSearchWrapper);
                stakeholderIds.add(stakeholderSearchWrapper.getId());
            }

            historyCount = stakeholderService.countHistoryEntryByStakeholders(stakeholderIds);
            notesCount = stakeholderService.countNoteEntriesByStakeholders(stakeholderIds);
            assignedProjects = projectService.findByStakeholderIds(stakeholderIds);

            for(StakeholderSearchWrapper dao : tmpModel) {
                dao.setHistoryCount(getHistoryCount(dao.getId()));
                dao.setNoteCount(getNoteEntriesCount(dao.getId()));
                dao.setProjects(getAssignedProjects(dao.getId()));
            }


            SolrDocumentList result = queryresponse.getResults();
            int numFound = (int) result.getNumFound();

            return tmpModel;
        } else {
            return tmpModel;
        }
    }

我想要的是懒惰加载不要只启动一次。它应该根据需要经常启动。我不知道在哪里我必须设置一些变量来实现这个功能。当我调试当前的代码时,加载函数只在页面刷新的第一次运行时被请求,并且比一次懒惰加载被调用,但随后什么都没有发生。

primefaces jsf-2 datascroller
1个回答
1
投票

我想我发现了窍门。检查这一行。

model.setRowCount(0);

用你想显示的最大数据量来设置模型的行数。

int totalNumberOfRegisters = this.count(/* relevant paramenters*/);
model.setRowCount(totalNumberOfRegisters);
© www.soinside.com 2019 - 2024. All rights reserved.