2

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?

Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
  • Please improve your question. It is not an [mcve]. You mention 'AddRecord.xhtml' but it is nowhere. You have a template that is nowhere (does it play a role? No? Remove it)... Your code contains many basic issues (`action="bean.methodName()"`. Start with something simple and make that work first. – Kukeltje Nov 20 '15 at 11:54
  • This is typo `action="bean.methodName()"` and if you checked the question thoroughly you will get i already mentioned `` .If Basic mistake would be there how could be page rendered? So You can say some typo is there but not basic mistakes. – Subodh Joshi Nov 20 '15 at 12:09
  • Not all 'basic' mistakes make the page not render... And the 'AddRecord' is indeed an omission on my side, sorry for that. And if there are such typos, I'm not investigating further. Anything could be a typo (how can I tell the difference between a typo and basic mistake? Create an mcve that is fully 100% what you run and not some partial copy/paste/edit... – Kukeltje Nov 20 '15 at 12:11
  • 1
    What does the anchor tag display for viewSource in . Please add activeIndex attribute in p:tabView and point it to #{bean.activeIndex} activeIndex should be int in your properly scoped managedBean, so that current tab is not hidden if page or partial page is re-rendered. – Mahendran Ayyarsamy Kandiar Nov 20 '15 at 18:28
  • @MahendranAyyarsamyKandiar Any example you know. – Subodh Joshi Nov 25 '15 at 11:26
  • Are you trying to navigate to to another inside the tab B itself? – Mahendran Ayyarsamy Kandiar Nov 25 '15 at 16:11
  • @MahendranAyyarsamyKandiar Yes right i am doing same after method call its showing active tab first one – Subodh Joshi Nov 25 '15 at 17:04
  • when u click on second tab is it showing AddRecord.xhtml? – Mahendran Ayyarsamy Kandiar Nov 25 '15 at 17:18
  • Yes Right but inside this second tab i have button when i click on this then its not showing other page its showing first tab again. – Subodh Joshi Nov 25 '15 at 17:24
  • It is not a good way to navigate. but i am not getting the answer i need What i am asking is 1. You clicked second tab 2. You clicked button inside it. 3. It shows same page with first tab. after this, do the following steps. a). click on second tab. IS it still showing button or addRecord.xhtml – Mahendran Ayyarsamy Kandiar Nov 25 '15 at 17:47
  • a). click on second tab. IS it still showing button or addRecord.xhtml ? It is showing addRecord.xhtml page – Subodh Joshi Nov 26 '15 at 04:11
  • Possible duplicate of [How do i set the active tab in Primefaces tabView?](http://stackoverflow.com/questions/6514352/how-do-i-set-the-active-tab-in-primefaces-tabview) – Kukeltje Nov 28 '15 at 09:35
  • As stated earlier, waaaay to much noise in this question and looking at the accepted answer, I'm proven right... Pure duplicate. http://stackoverflow.com/questions/6514352/how-do-i-set-the-active-tab-in-primefaces-tabview – Kukeltje Nov 28 '15 at 09:35

1 Answers1

2

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

Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
dileep H
  • 355
  • 1
  • 3
  • 9
  • If this is really just what the OP 'just needed, the question contained waaaaaay to much noise. The whole template stuff does not play a role. The addRecord page loading in tab B still won't happen since there is a full page 'get' request to 'addRecord'.and it then is a plain duplicate... http://stackoverflow.com/questions/6514352/how-do-i-set-the-active-tab-in-primefaces-tabview – Kukeltje Nov 28 '15 at 09:34