Primefaces 选项卡中的页面重定向问题?

Page redirect issue in Primefaces Tab?

这是我正在尝试的代码 运行

ChildTemplate.xhtml

<ui:composition template="../templates/home-template-new.xhtml" 
    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:fn="http://java.sun.com/jsp/jstl/functions"
    xmlns:p="http://primefaces.org/ui">
    <ui:define name="content">
        <h:outputStylesheet library="css" name="primeface_default.css" />
        <p:tabView dynamic="true" cache="true" id="tabView">
            <p:tab title="A">
                <ui:insert name="equipList">
                    <ui:include src="../AList.xhtml" />
                </ui:insert>
            </p:tab>
            <p:tab title="B">
                <ui:insert name="terminationList">
                    <ui:include src="../BList.xhtml" />
                </ui:insert>
            </p:tab>
        </p:tabView>
    </ui:define>
</ui:composition>

这里是BList.xhtml

<ui:composition 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:fn="http://java.sun.com/jsp/jstl/functions"
    xmlns:p="http://primefaces.org/ui">
<p:dataTable value="#{bean.fetchTemp()}" var="temp" reflow="true" resizableColumns="true" liveResize="true"
    id="table2">
    <p:column>  
          ........ 
          ........
    </p:column>
    <f:facet name="footer">
        <div class="divTableFooter" align="right" id="footerDiv6">
            <p:panelGrid>
                <p:commandLink id="create"
                    action="#{bean.methodName()}">
                </p:commandLink>
                <h:link value="LinkName" outcome="AddRecord" />
            </p:panelGrid>
        </div>
    </f:facet>
</p:dataTable>
</ui:composition>

现在让我来定义问题

现在我的活动标签是 B 当我点击 <p:commandLink/><h:link /> 它正在重定向并显示标签 A 虽然它应该在当前活动选项卡 B.

中显示 AddRecord.xhtml 页面

我的代码有什么问题?有人可以推荐吗?

您可以将 activeIndex 属性添加到您的 tabview 组件并使用 p:ajax 编写一个 tabchange 事件。请检查下面的代码

<h:outputStylesheet library="css" name="primeface_default.css" />
        <p:tabView dynamic="true" cache="true" id="tabView" activeIndex="#{bean.tabIndex}">
        <p:ajax event="tabChange" listener="#{bean.onTabChange}"  />
            <p:tab title="Equipment"  >
                <ui:insert name="equipList">
                    <ui:include src="../AList.xhtml" />
                </ui:insert>
            </p:tab>
            <p:tab title="Termination">
            <ui:insert name="terminationList">
                    <ui:include src="../BList.xhtml" />
                </ui:insert>
            </p:tab>
    </p:tabView>

在你的 bean 中定义 tabIndex 变量并实现 onTabChange 方法

private boolean popupEdit;
public final void onTabChange(final TabChangeEvent event) {
    TabView tv = (TabView) event.getComponent();
    this.tabIndex = tv.getChildren().indexOf(event.getTab());
}

希望对您有所帮助