【问题标题】:Page redirect issue in Primefaces Tab?Primefaces 选项卡中的页面重定向问题?
【发布时间】:2015-11-20 07:45:58
【问题描述】:

这是我要运行的代码

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,当我点击 &lt;p:commandLink/&gt;&lt;h:link /&gt; 它正在重定向并显示标签 A 而它应该显示 AddRecord.xhtml 页面在当前活动标签B

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

【问题讨论】:

  • 请改进您的问题。它不是minimal reproducible example。您提到了“AddRecord.xhtml”,但它无处不在。您有一个无处可去的模板(它起作用了吗?没有?删除它)...您的代码包含许多基本问题(action="bean.methodName()"。从简单的事情开始,然后首先使其工作。
  • 这是错字action="bean.methodName()",如果您彻底检查问题,您会得到我已经提到的&lt;h:link value="LinkName" outcome="AddRecord" /&gt;。如果出现基本错误,如何呈现页面?所以你可以说有一些错字,但不是基本错误。
  • 并非所有的“基本”错误都会导致页面无法呈现......而且“AddRecord”确实是我这边的一个遗漏,对此感到抱歉。如果有这样的错别字,我不会进一步调查。任何东西都可能是拼写错误(我如何区分拼写错误和基本错误?创建一个完全 100% 运行的 mcve,而不是部分复制/粘贴/编辑...
  • 中 viewSource 的锚标记显示什么。请在 p:tabView 中添加 activeIndex 属性并将其指向 #{bean.activeIndex} activeIndex 应该是 int 在您适当范围的 managedBean 中,以便在重新渲染页面或部分页面时不会隐藏当前选项卡。
  • @MahendranAyyarsamyKandiar 你知道的任何例子。

标签: jsf jsf-2 primefaces


【解决方案1】:

您可以将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());
}

希望对你有帮助

【讨论】:

  • 如果这真的正是 OP 所需要的,那么这个问题包含了很多噪音。整个模板的东西不起作用。选项卡 B 中的 addRecord 页面加载仍然不会发生,因为对 'addRecord' 有一个完整的页面 'get' 请求。然后它是一个简单的重复...stackoverflow.com/questions/6514352/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-03-19
  • 2012-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-23
  • 1970-01-01
相关资源
最近更新 更多