1

我很感兴趣是否可以以某种方式p:tabView使用 jsf ui 重复标签创建?我试图找到一个解决方案,如何创建从 Java 列表生成选项卡的循环。见这里。事实证明,这要复杂得多。有没有可能的解决方案?

4

3 回答 3

3

你可以这样做

你的豆子

public class BeanName implements Serializable {

public BeanName(){
 personList = new ArrayList<Person>();
 personList.add(new Person("ajay", "mumbai"));
 personList.add(new Person("hari", "pune"));
}

private List<Person> personList;

    public List<Person> getPersonList() {
        return personList;
    }

    public void setPersonList(
            List<Person> personList) {
        this.personList= personList;
    }

}


    public class Person{

    private String name;

    private String address;

        public Person(String name, String address) {
            this.name=name;
            this.address=address;
        }

    public String getName(){
      return name;
    }

    public void setName(String name){
      this.name=name;
    }

    public String getAddress(){
      return address;
    }

    public void setAddress(String address){
      this.address=address;
    }
}

Xhtml 中的代码

<p:tabView rendered="#{not empty beanName.personList}" value="#{beanName.personList}" var="list">               
    <p:tab title="#{list.name}">here your data</p:tab>
</p:tabView>
于 2014-12-17T12:05:43.140 回答
0

正如@p27 指出的那样,您可以使用p:tabView的valuevar属性来动态地为您放在value的集合中的每个项目呈现一个选项卡。这是我知道的唯一官方方法,因为 c:forEach 将在构建时应用,而不是像 ui:repeat 那样在渲染时应用(因此集合中不会有任何项目,也不会出现选项卡),并且 ui:repeat 在 p:tabView 组件中不起作用。

问题是,如果您想在同一个 p:tabView 内沿其他动态选项卡呈现一个或多个静态选项卡。如果在创建动态选项卡集合时不向动态选项卡集合添加虚拟项目(您将认为是静态的项目),则无法做到这一点,因此集合始终会将它们包含在其中。

于 2017-03-02T08:49:57.163 回答
-1

试一试。

<p:tabView id="tabView1">
    <ui:repeat value="#{controllerBean.docList}" var="doc"> 
        <p:tab  title="Godfather Part I">  
            <h:panelGrid columns="2" cellpadding="10">  
                <p:graphicImage  value="/images/godfather/godfather1.jpg" />  
                    <h:outputText   
                        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>  
    </ui:repeat>
</p:tabView>

这是一个带有 primafaces tabview 的简单 jsf 代码。

于 2013-06-01T22:01:17.110 回答