Primefaces dataTable inside tabView the row selection not working correctly

元气小坏坏 提交于 2019-12-24 16:09:26

问题


I have a tabView with a dynamic number of tabs which displays search results (in a class SearchInstance). Inside a tab there is also a tabView which displays a search result in different ways. One tab of this inner tabView shows the search results in a dataTable (as List). The rows are selectable. I propagate the selected search results in the table to the current SearchInstance object. Unfortunately the selected search results are only set correctly on the last tab. If I select a search result on a tab before the last tab, the ajax request does not hit the correct instance of SearchInstance and propagates an empty List even when some rows are selected.

Some shortened code:

The outer tabView:

<p:tabView id="searchTabViewId" activeIndex="#{searchBL.activeTabIndex}">
<p:ajax event="tabClose" listener="#{searchBL.onCloseTab}" />
<c:forEach items="#{searchBL.searchInstances}" var="curSearch">
    <p:tab closable="#{curSearch.isCloseable()}">
        <ui:include
            src="#{curSearch.closeable ? '/sections/search/searchInstanceTab.xhtml' : '/sections/search/firstSearchTab.xhtml'}">
            <ui:param name="curSearch" value="#{curSearch}" />
        </ui:include>
    </p:tab>
</c:forEach>

The tab on index 0 has a special meaning as search template and is not closable. So the first tab is always the same but has also a SearchInstance as model.On the 1st tab is no dataTable displayed. So the problem occurs on tab with index > 0.

searchInstanceTab.xhtml:

<h:form rendered="#{curSearch.isCloseable()}">
<h:panelGrid id="searchMaskInstanceOuterGridId" columns="1">
    <p:tabView id="listResultTabViewId">
        <p:tab id="listResultTabId">
            <ui:include src="/sections/search/resultList.xhtml">
                <ui:param name="curSearch" value="#{curSearch}" />
            </ui:include>
        </p:tab>
        ...
    </p:tabView>
</h:panelGrid>

The dataTable is inside resultList.xhtml

<p:dataTable id="searchResultTableId" scrollable="true" value="#{curSearch.getSearchResults()}" scrollHeight="300"
var="curSearchResult" sortMode="multiple" rowKey="#{curSearchResult.hashCode()}" draggableColumns="true"
resizableColumns="true" selection="#{curSearch.selectedSearchResults}" >

<p:ajax event="rowSelect" />
<p:ajax event="rowUnselect" />
<p:ajax event="toggleSelect" />
<p:ajax event="rowSelectCheckbox" />
<p:ajax event="rowUnselectCheckbox" />


<p:column style="width: 16px;">
    <p:rowToggler />
</p:column>
<p:column selectionMode="multiple" style="width: 16px; text-align:center" />

<p:columns value="#{curSearch.determinePrimaryPropertyNames()}" var="curPrimaryPropName"
    sortBy="#{curSearchResult[curPrimaryPropName].getValue()}"
    filterBy="#{curSearchResult[curPrimaryPropName].getValue()}" filterMatchMode="contains">

    <f:facet name="header">
        <h:outputText value="...." />
    </f:facet>
    ...
</p:dataTable>

I got really stuck here. Probably it is problematic to use c:forEach to render the tabs? With ui:repeat or with the built in iteration of tabView it does not work. Or is it not allowed to set the selected rows inside the SearchInstance iteration variable directly?

I am using JSF 2.2.10 and Primefaces 5.1.13. with juel el 2.2.7.

Regards Oliver

来源:https://stackoverflow.com/questions/29100822/primefaces-datatable-inside-tabview-the-row-selection-not-working-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!