Primefaces Accordion和TabView打开后问题

时间:2013-03-27 11:06:31

标签: jsf java-ee user-interface primefaces

我对Primefaces Accordion和TabView有疑问。当我将带有2个或更多Tabs的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”,但它无济于事。

1 个答案:

答案 0 :(得分:0)

您可以像这样使用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