Subodh Joshi
Subodh Joshi

Reputation: 13522

Page redirect issue in Primefaces Tab?

Here is the code which i am trying to run

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>

Here is the 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>

Now let me define the problem

Right now my active tab is B and when i am clicking the <p:commandLink/> or <h:link /> It is redirecting and showing tab A while it should show AddRecord.xhtml page in current active tab B.

What is wrong with my code ? Can someone suggest it?

Upvotes: 2

Views: 1497

Answers (1)

dileep H
dileep H

Reputation: 355

You can add activeIndex attribute to your tabview component and write a tabchange event using p:ajax .Please check the below code

<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>

in your bean define tabIndex variable and implement the onTabChange method

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

Hope this will help you

Upvotes: 2

Related Questions