2014-03-19 113 views
0
public class Tabs { 
     public Tabs() { 
      fc = FacesContext.getCurrentInstance(); 
      tabView = (TabView) fc.getApplication().createComponent(
        "org.primefaces.component.TabView"); 
      Tab tab1 = new Tab(); 
      tab1.setTitle("Default tab"); 
        Tab tab2 = new Tab(); 
      tab2.setTitle("Manage Favorites"); 
      tab2.setClosable(true); 
      tabView.getChildren().add(tab1); 
      tabView.getChildren().add(tab2); 

      tabView.setActiveIndex(0); 
     } 

    public TabView getTabView() { 
     return tabView; 
    } 

    public void setTabView(TabView tabView) { 
     this.tabView = tabView; 
    } 

    public void addTabs() { 
     Tab tab3 = new Tab(); 
     tab3.setTitle("Manage Favorites"); 
     tab3.setClosable(true); 
     tabView.getChildren().add(tab3); 
     System.out.println("Called"); 
    } 

    FacesContext fc; 
    TabView tabView; 
} 

这是我们在tabview中添加选项卡的bean。作品完全没问题..在PrimeFaces选项卡视图

<p:tabView id="mytabview" orientation="left" binding="#{Tabs.tabView}" 
      style="position:relative" rendered="true" styleClass="tabs"> 
     </p:tabView> 

这显示标签,但它完全是空的。我想在这些标签中添加面板网格。

问题是:如何在编程结束时添加一个panelgrid,以便标签视图显示一些信息。

回答

0

如果您只是在<p:tabView>标记中定义要使用的选项卡,那么是否更容易?

例子:

<p:tab id="tab1" title="Godfather Part I"> 
    <h:panelGrid columns="1" cellpadding="10"> 
     <h:outputText id="tab1Text" 
      value="The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding. 
      His beloved son Michael has just come home from the war, but does not intend to become part of his father's business. T 
      hrough Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those who give respect, 
      but given to ruthless violence whenever anything stands against the good of the family." /> 
    </h:panelGrid> 
</p:tab> 

<p:tab id="tab2" title="Godfather Part II"> 
    <h:panelGrid columns="1" cellpadding="10"> 
     <h:outputText id="tab2Text" value="Francis Ford Coppola's legendary continuation and sequel to his landmark 1972 film, The_Godfather, parallels the young Vito Corleone's rise with his son Michael's spiritual fall, deepening The_Godfather's depiction of the dark side of the American dream. 
     In the early 1900s, the child Vito flees his Sicilian village for America after the local Mafia kills his family. Vito struggles to make a living, legally or illegally, for his wife and growing brood in Little Italy, 
     killing the local Black Hand Fanucci after he demands his customary cut of the tyro's business. With Fanucci gone, Vito's communal stature grows."/> 
    </h:panelGrid> 
</p:tab> 

定义在JSF页面中的标签会更容易,因为你会在右边的页面中定义它,而不是方法调用它。只有当您需要更完善的实现来改变组件的行为时,才能通过方法调用它。

我得到这个例子从这里:http://primefaces.org/showcase/ui/tabview.jsf

祝你好运!