2014-03-19 69 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

祝你好運!