【问题标题】:Primefaces Datatable within Tabview - initial sort on second tab doesnt workTabview 中的 Primefaces 数据表 - 第二个选项卡上的初始排序不起作用
【发布时间】:2013-05-18 00:58:37
【问题描述】:

我有一个 tabView,其中每个选项卡都包含一个数据表。我是这样设置的

<p:tabView id="tabView" styleClass="manage-tab-view" prependId="false" 
        activeIndex="#{managementTabBean.activeIndex}" dynamic="true" cache="false">
<p:tab id="users" title="#{msg['TeamManagement.Tabs.Users']}" >
            <ui:include src="tab1.xhtml" />
        </p:tab>
<p:tab id="athletes" title="#{msg['TeamManagement.Tabs.Athletes']}">
            <ui:include src="tab2.xhtml" />
</p:tab>
</p:tabView>

在每个选项卡中,我试图显示一个数据表。现在我的设置是这样的:

Tab1:

<h:form id="userProfileViewForm" prependId="false">
    <p:dataTable var="userProfile" value="#{userProfileListBean.objects}"
        id="userProfilesTable" sortBy = "#{userProfile.lastName}" sortFunction = "#{userProfileListBean.sortUserLastName}" sortOrder = "ascending" lazy="true">

        <p:column sortBy="#{userProfile.lastName}" sortFunction = "#{userProfileListBean.sortUserLastName}" id="userName">
p:commandLink>
             <p:commandLink rendered="#{!appContextBean.isCWContext()}"
                    onclick="window.location.href='userBS.xhtml?id=#{userProfile.id}'">
                    <div class="clickable-cell">
                        <h:outputText
                        value="#{userProfile.firstName} #{userProfile.lastName}" />
                    </div>
            </p:commandLink>
        </p:column>

...more columns...

Tab2:相似数据表

<p:dataTable var="athlete" value="#{athleteListBean.objects}"
        tableStyle="width:auto" sortBy="#{athlete.getDisplayName()}" sortFunction = "#{athleteListBean.sortAthleteDisplayName}" id="athletesTable" 
        sortOrder="#{athleteListBean.getListSortOrderDesc()}" lazy="true" paginator="true" rows="15" paginatorPosition="bottom"
            paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}">

        <p:column sortBy="#{athlete.getDisplayName()}" sortFunction = "#{athleteListBean.sortAthleteDisplayName}" id="athleteColumn">
<h:outputText styleClass="athlete-listing athlete-name" value="#{athlete.firstInitial} #{athlete.lastName}" />
</p:column>

如您所见,我为两个数据表设置了自定义初始排序功能。

由于某种原因,第一个选项卡排序函数被调用,而第二个选项卡排序函数没有。在我交换 tabview 中的选项卡后,tab2 排序函数被调用,但 tab1 没有。

基本上初始排序函数仅在第一个选项卡的数据表上调用,基于选项卡视图中选项卡的顺序。谁能告诉我为什么会这样?

感谢您的帮助。

【问题讨论】:

  • 可能是因为你只有一个 h:form 标签。尝试使用将每个表插入到一个 h:form 标记中。问候,
  • 我没有将代码粘贴到第二个数据表上方,因为我没有意识到它是相关的。但是我的每个数据表都有自己的表单标签。表格的设置方式完全相同。
  • 我也遇到同样的问题,你解决了吗?

标签: java jsf primefaces datatable tabview


【解决方案1】:

我遇到了类似的问题,在我的情况下,第二个选项卡上有一个带有 p:columnToggler 的 p:dataTable,单击按钮隐藏或显示列显示为黑色,无法删除列。

我找到的解决方案是在 p:TabView 中的 p:ajax 中添加事件“tabChange”

这样问题就解决了,我已经在 p:columnToggler 上正常工作了。

也许您解决了 p:dataTable 的顺序问题。

我把我的代码放在这里:

<p:tabView effect="fade" effectDuration="fast"  prependId="false">
    <p:ajax event="tabChange" update="@this"/>
    <p:tab title="#{text['liquidacionForm.tabDatosLiq']}">
       <ui:include src="/datosLiquidacion.xhtml"></ui:include>
     </p:tab>
    <p:tab title="#{text['liquidacionForm.tabEstanciasLiq']}">
       <ui:include src="/estanciasLiquidadas.xhtml"></ui:include>
   </p:tab>
</p:tabView>

【讨论】:

    【解决方案2】:

    我认为,由于 EL(表达式语言)部分提供了完整的方法名称,根本不会调用您的第二个选项卡排序。

    因此,您需要删除实际方法名称并执行 getter 部分,即

    而不是{athleteListBean.getListSortOrderDesc() 使用{athleteListBean.listSortOrderDesc}

    第二个标签使用下面的代码。

     <p:dataTable var="athlete" value="#{athleteListBean.objects}"
        tableStyle="width:auto" sortBy="#{athlete.displayName}" sortFunction = "#{athleteListBean.sortAthleteDisplayName}" id="athletesTable" 
        sortOrder="#{athleteListBean.listSortOrderDesc}" lazy="true" paginator="true" rows="15" paginatorPosition="bottom"
            paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}">
    
        <p:column sortBy="#{athlete.displayName}" sortFunction = "#{athleteListBean.sortAthleteDisplayName}" id="athleteColumn">
    

    【讨论】:

      猜你喜欢
      • 2018-04-11
      • 2013-04-17
      • 2015-10-18
      • 2016-01-03
      • 2013-10-19
      • 2015-12-20
      • 1970-01-01
      • 1970-01-01
      • 2011-06-28
      相关资源
      最近更新 更多