jsf ui用p:tabView重复

时间:2012-10-29 21:58:21

标签: java jsf jsf-2 primefaces

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

3 个答案:

答案 0 :(得分:1)

你可以这样做

你的豆子

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>

答案 1 :(得分:0)

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

问题是,如果要在同一个p:tabView中的其他动态选项卡上渲染一个或多个静态选项卡。如果没有在创建动态选项卡集合时将虚拟项目(您将考虑静态的项目)添加到动态选项卡集合中,则无法完成此操作,因此集合始终将它们放在内部。

答案 2 :(得分:-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代码。