简体   繁体   中英

Primefaces UI:repeat not working

I'm trying to create accordionPanel in Primefaces.And i'm trying to create that using ui:repeat so i can create panel tabs dynamically.But somehow my code doesn't works, accordionPanel is empty and does not have any tabs.can any one give me the reason or point me how to achieve this.

here my bean.

@ManagedBean(name = "divisionList")
public class Divisions implements Serializable {

private List<String> divStrings;

public List<String> getDivStrings() {
        return divStrings;
    }
    public Divisions(){
        divStrings=new ArrayList<String>();
        divStrings.add("Division A") ;
        divStrings.add("Division B");
   }

}

and in my xhtml :

<p:accordionPanel >
         <ui:repeat value="#{divisionList.divStrings}" var="divis">
               <p:tab title="#{divis}">
                            Content
               </p:tab>
         </ui:repeat>
</p:accordionPanel>

EDIT:

But when it print like this its working :O

<ui:repeat value="#{divisionList.divStrings}" var="divis">
    <h:outputText value="#{divis}" />
</ui:repeat>

There is no problem with your ui:repeat, don't wrap it inside an empty

<p:accordionPanel >

Or remove the uirepeat and fill in the value of your accordionPanel

Do like this

<p:accordionPanel value="#{test.divStrings}" var="divis" >
           <p:tab title="#{divis}">
                        Content
           </p:tab>
</p:accordionPanel>

In stead of initializing the list in the constructor, try initializing it in a @PostConstruct annotated method.

   @PostConstruct
   public void init(){
        divStrings=new ArrayList<String>();
        divStrings.add("Division A");
        divStrings.add("Division B");
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM