【问题标题】:Primefaces Accordion and TabView issue after openPrimefaces Accordion 和 TabView 打开后的问题
【发布时间】:2013-03-17 10:39:51
【问题描述】:

我对 Primefaces Accordion 和 TabView 有疑问。当我将带有 2 个或更多选项卡的 TabView 放入 Accordion 面板并第一次打开我的页面时,所有选项卡都会同时显示。然后,当我通过单击其他标题更改选项卡时,一切都恢复正常。

我的结构是:

<p:accordionPanel>
  <p:tab>
   <p:tabView>
     <p:tab id="tab1">
       Content 1 here
     </p:tab>
     <p:tab id="tab2">
       Content 2 here etc.
     </p:tab>
   </p:tabView>
  </p:tab>
<p:accordionPanel>

我尝试使用 activeIndex="0",但无济于事。

【问题讨论】:

  • 您的代码不能在第一行工作,因为标题对于标签是强制性的。第二,怎么会有人知道你用的是什么版本?
  • 我正在使用 Primefaces 版本:3.5 添加标题后它无论如何都不会工作。
  • 检查页面加载时是否有一些javascript错误,这可能会导致PF组件出现一些异常行为。也尝试像PF Showcase 节目那样做,这绝对可以。
  • 为我工作(在所有&lt;p:tabs/&gt; 上设置title)。为您的问题添加更多上下文。在你看来,还有其他东西坏了。还要检查你的 javascript 控制台是否有错误。

标签: jsf jakarta-ee user-interface primefaces


【解决方案1】:

您可以像这样使用 JSF Accordion 的 activeIndex 属性:

<p:accordion id="accordionView" activeIndex="#{myBean.tabIndex}">

并在您的支持 bean 中放入 @PostConstructor 进行搜索

  public static final String INDEX_PARAM = "index_get_param";

  @Inject
  private transient HttpServletRequest httpReq = null;
  private int tabIndex = 0;
  @PostConstruct
  public void init()
  {

    if (httpReq != null)
    {
      String indexParam = httpReq.getParameter(INDEX_PARAM);
      if (indexParam != null)
      {
        searchTypeParameter = searchTypeParameter.toUpperCase();
        if (indexParam.equals("FIRST")
          tabIndex = 0;
        if (indexParam.equals("SECOND")
          tabIndex = 1;

      }
    }
  }

  public int getTabIndex()
  {
    return tabIndex;
  }

它也适用于p:tabView

【讨论】:

    猜你喜欢
    • 2012-02-28
    • 2011-07-10
    • 2021-07-31
    • 2010-09-27
    • 1970-01-01
    • 1970-01-01
    • 2017-08-20
    • 2015-01-06
    • 1970-01-01
    相关资源
    最近更新 更多