1

I'm interested is it possible somehow to create p:tabView with jsf ui repeat tag? I tried to find a solution how to create loop which generates tabs from Java list. See here. It turns out that this is much more complicated. Is there any possible solution?

2
  • What exactly have you tried? Please post some code here
    – kolossus
    Oct 30, 2012 at 5:36
  • why you want to use the ui:repeat tag if the value attribute of the p:tabView works with collections?
    – Akos K
    Oct 30, 2012 at 5:52

3 Answers 3

3

you can do like following

your bean

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;
    }
}

code in 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>
0

As @p27 points out, you can use value and var attributes of p:tabView to dynamically render one tab per item in the collection you put on value. This is the only official way to do this that I am aware, since c:forEach will be applied in build time and not in render time like ui:repeat (thus you won't have any items inside the collection and no tabs will appear), and ui:repeat won't work inside p:tabView component.

Problem is if you want to render one or more static tabs along other dynamic tabs inside the same p:tabView. That can't be done without adding dummy items (those that you will consider static) to the dynamic tab collection whenever it is created so in that way the collection always will have them inside.

-1

give a shot to this.

<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>

this is a simple jsf code with primafaces tabview.

2
  • I've tried this too but it doesn't work (any more?). Everything inside the <ui:repeat> is ignored.
    – MathiasJ
    Jun 18, 2015 at 8:22
  • This was never supposed to work. p:tabView only 'knows' what to do with p:tab children. Not a ui:repeat
    – Kukeltje
    Mar 2, 2017 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.