在PrimeFaces选项卡视图上

时间:2014-03-19 10:04:24

标签: jsf primefaces

    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。工作得很好..

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

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

问题是:如何在编程端添加panelgrid,以便选项卡视图显示一些信息。?

1 个答案:

答案 0 :(得分: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

祝你好运!